get the id from an element in repeated group

elle

Member
Hi there,

I try to call a function in my form_14.js
I have to know, wich element of wich repeated line is calling the function. So for testing I wrote in the JS-Tab of the element for the change event a simple:
Code:
provision(this.id);
to get the id from the called element into the function provision(call) in my form_14.js.

But all I get is an "undefined"...

Can you help me please?

Kind regards
--Elle--
 
It'd be in this.element.id. But as you quite often find you need "other stuff", typically passing in just 'this' is he;pful. In the context of calling a function from the Fabrik element JS, 'this' will be the Fabrik element object, and within that object, 'element' will be the DOM element, that has the id.

Code:
provision(this);

Code:
function provision(el) {
   id = el.element.id;
   val = el.getValue();
   // rest of code
}

So as an example, el.getValue() calls the Fabrik object's getValue() method, which is often a useful thing to do.

-- hugh
 
BTW, another useful function is el.getRepeatNum(), which will give you the group repeat suffix. So if you need to "do stuff" to other elements on that new group in your JS, you can ...

Code:
var rnum = el.getRepeatNum();

... and then build other element id's and get the objects for them, and (say) set their value ...

Code:
var other_element_id = 'mytable___other_element_' . rnum;
var other_el = Fabrik.getBlock('form_123').formElements.get(other_element_id);
other_el.update('some value for other_el');

Also note the use of Fabrik.getBlock('form_X') to get the main Fabrik object for your form, and formElements.get() to get the desired element object. Those objects are the equivalent of the 'el' you passed in to your function, for any element object on the form.

And this being JavaScript, you can get really cryptic and do it all on one line ...

Code:
Fabrik.getBlock('form_123').formElements.get('mytable___other_element_' . el.getRepeatNum()).update('some value for other_el');

:)

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top