YesNo Checkbox Javascript

emcguire

Member
Hey Guys,

I have a YesNo element that is defaulted to NO when record is entered, but when you load the form to update, I want it to set itself to yes. (there is a specific reason I need to do it this way)

I had this working perfectly until recently, I'm not sure what changed. Here is the JS I was using to make that happen (it worked)

onLoad :

JavaScript:
Fabrik.getBlock('form_13').formElements.get('nab_account_approvals___approve').update('1') ;

sometime recently this just stopped working, and it just stays on NO.

Do I need to update this code? or something else going on here?
 
Oh - I originally had this (without formElements)

either way doesnt work anymore

JavaScript:
Fabrik.getBlock('form_13').element.get('nab_account_approvals___approve').update('1') ;
 
I also tried how it was outlined in the wiki ;

also didn't work


Code:
var account= Fabrik.getBlock('form_13').formElements.get('nab_account_approvals___approve');
value = account.get('nab_account_approvals___approve');
approve.update('1');
 
I can confirm this issue.
I wonder how long this has been broken and exactly what 'broke' it?

Getting the value from a YesNo element is addressed here in the Fabrik Wiki...
Accessing sub elements in checkboxes/radio buttons
However changing the value (at least how they can be changed in the current version of J!/Fabrik) isn't.

@emcguire: A workaround until this is fixed would be to just trigger the click event on the subelement ('Yes') label via javascript.
JavaScript:
Fabrik.getBlock('form_13').formElements.get('nab_account_approvals___approve').subElements[1].parentElement.click() ;
I'm not sure if that would work in the element onload event - but it worked for me when put inside a fabrik.form.elements.added event in the form_x.js file - e.g.
JavaScript:
requirejs(['fab/fabrik'], function () {
    Fabrik.addEvent('fabrik.form.elements.added', function (block) {
        Fabrik.getBlock('form_13').formElements.get('nab_account_approvals___approve').subElements[1].parentElement.click() ;
    });
}

EDIT Note: Tested - The first example works in onload event of element javascript.
 
Last edited:
Meh.

This is one of those things which is extremely site template dependent. Every template out there has different (and conflicting) ways of handling button group CSS handling. One of the shortcomings of Bootstrap is that this isn't built in. If you use button groups, your code has to handle applying the classes when the selection is changed. Which of course means that Fabrik has to figure out a way of doing it which works for all templates.

I may just rip out our code which handles that on update(), and just fire a click event.

-- hugh
 
So it would be good to know if @emcguire has also changed templates since he last updated?
Personally, I don't really remember the last time I tested a repeat group like that.
 
Thanks Guys,

Bauer's first code block did the trick. Until the next template update haha.

Since this was working and now it's not, it definitely smells of template/bootstrap conflicts with the template. I may have updated the template framework at some point. it is a Shape5 Vertex framework.

Thanks Fellas, appreciate the guidance!
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top