# Another way for Htmldialog get\_element\_value. Need Help

**URL:** <https://forums.sketchup.com/t/another-way-for-htmldialog-get-element-value-need-help/34618>\
**Category:** Ruby API\
**Tags:** make-2017\
**Created:** [November 24, 2016, 9:52am UTC](https://forums.sketchup.com/t/another-way-for-htmldialog-get-element-value-need-help/34618 "2016-11-24T09:52:25Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [March 14, 2018, 2:25pm UTC](https://forums.sketchup.com/t/another-way-for-htmldialog-get-element-value-need-help/34618/17 "2018-03-14T14:25:12Z")

</div>

> [@Alternative to get\_element\_value method for HtmlDialog](https://forums.sketchup.com/t/alternative-to-get-element-value-method-for-htmldialog/33753/14):
>
> Moreover the whole construct with callback is split over three methods, hardly understandable and maintainable. Actually you would rather want to have the callback together with get\_element\_value than separate (either as callback function parameter or as callback that can be registered on a returned promise).

[His code](https://forums.sketchup.com/t/alternative-to-get-element-value-method-for-htmldialog/33753/10) is based upon my example (in this thread.)

It would be a messy example if it used one method.

**I chose for this example** , to use a “trigger” method, 1 callback that receives the value, and a separate method that can process any of the values in the **`@values`** hash.

> **_Asside_** : I know, you could actually have the value parameter optional, and then have a conditional inside the method, and then 1 arg makes it a “trigger” and 2 args and it is being called from the dialog’s JS.  
> But this is not as simple an example as I show above.

[In my example](https://forums.sketchup.com/t/another-way-for-htmldialog-get-element-value-need-help/34618/6) I choose to have the “receive\_value()” method first quickly assign the value to a hash (whose keys are id strings,) and then call a **separate** “process\_value()” method, because it may likely be needed to have other methods initiate the processing of values at other times than when a dialog receives a value. (Such as triggered by a API observer, etc.)

It also occured to me that sometime, it may be advantageous to iterate the **`@values`** hash and process all values. This again makes sense to have the process routine in a separate method than the receive callback from JS.

**EDIT** : I’ve added a process iterator method to the example to illustrate this point …

```ruby
    def process_values
      @values.keys.each { |id| process_value(id) }
    end

```

* * *

However, if you have a better idea / example, **PLEASE post it rather than tearing mine down**.

---

_[View the full topic](https://forums.sketchup.com/t/another-way-for-htmldialog-get-element-value-need-help/34618)._
