javascript in form_x.js to enable/disable fields

bggann

Active Member
I'm trying to use a form java script file to enable/disable certain fields based on another.
I can use this to hide/show, but I don't like that because it messes with the screen format.
But I can't figure out how to set a field to enabled or disabled in form_x.js
Here is my code.
I get an error that 'enable' is not a fuction.
if I use var.hide() or var.show() that works.

I've tried other formats - like state.enable(true); state.enable=true;
Kinda puffin in the dark here.

Help please/

function Manage_Owner_Country_Fields(el) {
// This function enables or disables the other country, other state and state feilds based on country
var country = el.getValue();
var state = el.form.formElements.get('stca_htf___state');
var other_state = el.form.formElements.get('stca_htf___other_state_province');
var other_country = el.form.formElements.get('stca_htf___other_country');

if (country != 'Other') {
state.enable();
other_state.disable();
other_country.disable();
other_state.update('');
other_country.update('');
}
else {
state.disable();
other_state.enable();
other_country.enable();
}
}
 
Nope - no joy.
state.disabled = true;
runs - but does nothing. No error is thrown in javasctipt.
state.disable() or state.enable() throws a unknown function.

state.hide() .show() .toggle() are all functions defined in runs in element.js
eg:

hide: function () {
var c = this.getContainer();
if (c) {
jQuery(c).hide();
jQuery(c).addClass('fabrikHide');

}
},

I cannot find the equivalent for enable or disable. These function are available in the element javascript editor when you "build" the function by selecting items, so if I could figure out what it was doing.....
 
Well - by dint of a lot of debugging tracing - I found a way to make it work.
I traced the code that executes when you "build" a javascript function on an element to "disable" a field.
That called code like:

jQuery('#' + fieldID).prop('disabled', false); where fieldID is actually the full element name (table___element)

So in my form javascript I put.
jQuery('#' + 'owners_table___state').prop('disabled', false);
jQuery('#' + 'owners_table___other_state_province').prop('disabled', true);
jQuery('#' + 'owners_table___other_country').prop('disabled', true);

I tried to do jQuery("#" + state.baseElementID).prop('disabled',true/false) in because the element name is in there.
I can see it in the debugger, but it did not work. But that's kind of okay - because I have to type in the actual element name el.form.formElements.get('stca_htf___other_state_province');

My final code is
function manageOwnerCountryFields(el) {
// This function enables or disables the other country, other state and state feilds based on country
var country = el.getValue();
if (country != 'Other') {
jQuery('#' + 'owners_table___state').prop('disabled', false);
jQuery('#' + 'owners_table___other_state_province').prop('disabled', true);
jQuery('#' + 'owners_table___other_country').prop('disabled', true);
other_state.update('');
other_country.update('');
}
else {
jQuery('#' + 'owners_table___state').prop('disabled', true);
jQuery('#' + 'owners_table___other_state_province').prop('disabled', false);
jQuery('#' + 'owners_table___other_country').prop('disabled', false);
}
}

IT is called by manageOwnerCountrieFields(this); in the javascript of the controlling element.

I may need to add a "repeat" to some of these elements because they are in repeating groups.

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

Thank you.

Members online

Back
Top