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.

Moderator: ooffick

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

Required Fields

Post by 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: 1389
Joined: Sat Oct 28, 2006 11:16 pm
Location: Texas
Contact:

Re: Required Fields

Post by 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/pr ... ails/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

Post by Alfred » Sun Feb 13, 2011 11:57 am

Thanks, that did the trick !


Locked

Return to “Joomla! 2.5 Coding”