javascript code

enzo2016

Member
Hello,
I have used the following code for hide/show:



var form = Fabrik.getBlock('form_12');

var v = form.formElements.get(?customers___contacts').getValue();



if (v === 'phone') {

form.formElements.get(?customers___fax?).hide();

form.formElements.get(?customers___phone').show();

form.formElements.get(?customers___email').hide();

}



if (v === 'email') {

form.formElements.get(?customers___fax?).hide();

form.formElements.get(?customers___phone').hide();

form.formElements.get(?customers___email').show();

}



if (v === 'fax') {

form.formElements.get(?customers___fax?).show();

form.formElements.get(?customers___phone').hide();

form.formElements.get(?customers___email').hide();

}



if (v === 'address') {

form.formElements.get(?customers___fax?).hide();

form.formElements.get(?customers___phone').hide();

form.formElements.get(?customers___email').hide();

}




It doesn't work. I have tried it either with "click" and "load" action for a radiobutton element. Is it correct?




Thanks


Enzo
 
Into the field where it should be pasted or written... I think it is the only field where it can be written.

Thanks

Enzo
 
I run my JS code from form_X.js file.
I use plain js code, but now tried to do it through code from the fabrik. I failed completely, but should work.
I know that is not elegant, but work.

JavaScript:
requirejs(['fab/fabrik'], function() {
    jQuery('#your_radio_element_id').on('change', function(){ // select the radio element by its id
        form = Fabrik.getBlock('form_12');
        val = form.elements.get(customers___contacts').getValue();
        //console.log(val);
        if(val=='phone'){
             form.formElements.get(?customers___fax?).hide();

             form.formElements.get(?customers___phone').show();

            form.formElements.get(?customers___email').hide();
        }
       ....
       ....

    });   
});

I pasted part from your code in my editor and find this:
http://prntscr.com/d9ua10
May be this broke your code.
 
Thanks so much for the time you have dedicated to me. You have solved my thread.
The problem was that I used the apostrophe, but after looking at your snapshot, I have noted that there was a slight difference between the sign into the red square and the correct sign.
I have solved by copying and pasting the correct sign, but do you know a way how to type it through keyboard?


For readers who are learning how to use javascript code:
The code logic posted in my previous post is ok for the change event, but for load event I have just now discovered that the logic is similar to the change event, but for the radiobutton element, the code must be:

if (v === '') {


Thanks again startpoint
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top