The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Required Fields
PostPosted: Sat Feb 12, 2011 9:06 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Fri Aug 04, 2006 11:28 am
Posts: 142
In the component I'm developing I'm adding contacts in the backend, name and email are required fields.

In the mycontacts.xml, I have set the required="true" like:

Code:
<field
            name="name"
            type="text"
            label="COM_MYCONTACTS_CONTACT_NAME"
            description="COM_MYCONTACTS_NAME_DESC"
            size="50"
            class="inputbox"
            required="true"
            default=""
         />


However, when I leave the fields empty and try to save I do not get the expected behavior.
Instead of the label and the field border to turn red, I get a Field required: Name warning.

What am I missing here ?


You do not have the required permissions to view the files attached to this post.


Last edited by Alfred on Sun Feb 13, 2011 11:57 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Required Fields
PostPosted: Sat Feb 12, 2011 10:25 pm 
User avatar
Joomla! Ace
Joomla! Ace

Joined: Sat Oct 28, 2006 11:16 pm
Posts: 1248
Location: Texas
You'll need to include form validation javascript php.
Code:
JHtml::_('behavior.formvalidation');

Then you have to instigate the form validation javascript in your resulting file.
Code:
function submitbutton(task)
{
    if (task == 'formid.cancel' || document.formvalidator.isValid(document.id('formid'))) {
        submitform(task);
    }
}


Editing because I forgot to mention that your task needs to be appropriate to your controller named task and the document.id('formid') needs to match your form id.

So if your controller is named 'contactitem', then the task should == 'contactitem.cancel' and if your form id is 'contactitemform' then you should have document.id('contactitemform').

_________________
My extensions: http://extensions.joomla.org/extensions/owner/stutteringp0et
Honk if this signature offends you.


Top
 Profile  
 
 Post subject: Re: Required Fields
PostPosted: Sun Feb 13, 2011 11:57 am 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Fri Aug 04, 2006 11:28 am
Posts: 142
Thanks, that did the trick !


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 



Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group