Required Fields

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderators: ooffick, dam-man

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
User avatar
Alfred
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 142
Joined: Fri Aug 04, 2006 11:28 am
Contact:

Required Fields

Postby Alfred » Sat Feb 12, 2011 9:06 pm

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: Select all

<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.

User avatar
stutteringp0et
Joomla! Ace
Joomla! Ace
Posts: 1303
Joined: Sat Oct 28, 2006 11:16 pm
Location: Texas
Contact:

Re: Required Fields

Postby stutteringp0et » Sat Feb 12, 2011 10:25 pm

You'll need to include form validation javascript php.

Code: Select all

JHtml::_('behavior.formvalidation');

Then you have to instigate the form validation javascript in your resulting file.

Code: Select all

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/profile/profile/details/18398
Honk if this signature offends you.

User avatar
Alfred
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 142
Joined: Fri Aug 04, 2006 11:28 am
Contact:

Re: Required Fields

Postby Alfred » Sun Feb 13, 2011 11:57 am

Thanks, that did the trick !


Return to “Joomla! 2.5 Coding”

Who is online

Users browsing this forum: No registered users and 0 guests