How manipulate widget attributes via javascript?
Archived from the Xataface Users forum.
clawes — Thu Jun 07, 2012 6:51 pm
I have created an onChange javascript function that shows the grant_mailbox_access field and label only if a successor (successor_id) is chosen. See code snippet below.
However, I also need to make the ‘grant_mailbox_access’ field mandatory (required) whenever it is displayed and not required when it’s hidden.
I don’t know what javascript method/function to use to manipulate this widget’s required attribute.
TIA
- Code: Select all
function hideFields() { var successor = document.getElementById('successor_id').value; if (successor.length == 0){ document.getElementById('grant_mailbox_access').style.display = 'none'; document.getElementById('grant_mailbox_access_form_row').style.display = 'none'; } else { document.getElementById('grant_mailbox_access').style.display = ''; document.getElementById('grant_mailbox_access_form_row').style.display = ''; } }
</code snippet>
shannah — Fri Jun 08, 2012 1:12 pm
You could add your own javascript validation.
- Code: Select all
jQuery('#grant_mailbox_access').closest('form').submit(function(){ if ( jQuery('#successor_id').val() && !jQuery('#grant_mailbox_access').is(':checked') ){ alert('Grant mailbox access is required.'); return false; } return true; });
(Code untested but should work…)
-Steve