How manipulate widget attributes via javascript?

A place for users and developers of the Xataface to discuss and receive support.

How manipulate widget attributes via javascript?

Postby 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 snippet>
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>
clawes
 
Posts: 22
Joined: Mon May 07, 2012 12:02 pm

Re: How manipulate widget attributes via javascript?

Postby 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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 5 guests

Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved