hide submit button from radiobutton value

leblancphil

Member
Hi
I followed forum exemple to try to hide submit button of my form 204 when the radiobutton admin3_historique___etat' value is 1

I have put this in form_204.js
Code:
function showHideSave() {
    var value = form_204.formElements.get('admin3_historique___etat').getValue();
    if (value != 1) {
        form_204.getElements('input[name=submit]')[0].show();
    }
    else if (value == 1) {
        form_204.getElements('input[name=submit]')[0].hide();
    }
}
and showHideSave() in javascript onload of "admin3_historique___etat"
the javascript console says about .get('admin3_historique___etat').getValue(); Cannot read property 'get' of undefined

Thanks for your attention
 
You must be working from a very, very old example. The 'form_204' variable won't exist.

There's two ways you can get the form object. The generic one is to us getBlock for your form's id ...

Code:
var form = Fabrik.getBlock('form_204');
var value = form.formElements.get('admin3_historique___etat').getValue();

The other is to pass the element object ("this") in when you call your function ...

Code:
showHideSave(this);

The element object has a reference to the form in it, so in your function,

Code:
function showHideSave(el) {
   var value = el.form.formElements.get('admin3_historique___etat').getValue();
...
}

However, once you are passing that element object into your function, and as you are only needing to get the value for "this" element, you don't need the form object at all, you can just do the getValue() directly on the object ...

Code:
function showHideSave(el) {
   var value = el.getValue();
...
}

Also, we have a function in the form to get you the button ...

Code:
el.form._getButton('Submit')

So ...

JavaScript:
function showHideSave(el) {
   if (el.getValue() === '1') {
      el.form._getButton('Submit').hide()
   }
   else {
      el.form._getButton('Submit').show()
   }
}

-- hugh
 
Thank you, I have tried this
In my element javascript
Code:
showHideSave(this);

and in my form_204.js

Code:
function showHideSave(el)
{
   var value = el.form.formElements.get('admin3_historique___etat').getValue();
    var value = el.getValue();
   if (el.getValue() === '1') {
      el.form._getButton('Submit').hide()
   }
   else {
      el.form._getButton('Submit').show()
   }
}
But no result
 
Can you point me at the form? If it's on your edim site, my credentials don't seem to work any more.

And, remove the two 'var' lines, you don't need them, if that function is being called from the 'etat' element. The 'el' param is the element object. No need to fetch it from the elements array on the form.

-- hugh
 
I don't see a form_X.js file loading on either forms that list page you pointed me at links to (with the -> button or the Preinsrcire button).

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

Thank you.

Members online

No members online now.
Back
Top