A couple of newbie questions

LarryD 20 May, 2009
1) I am using the well known PHP code (below) to display the categories. However I would like make this drop down required. If I am correct there is no markup for me to use 'required'. How can I make my categories required?


        echo JHTML::_('list.category', 'catid', '21');


2) If the user fails image verification the file upload element gets cleared. I have 'try to republish' selected and it works for the input box, drop down and text area. Just not for the file upload element.

3) Also, when the image verification fails the page refreshes. In my case the form is not at the top of the page so the user does not immediately see the image verification failure notice. Any ideas on how to deal with this?
Max_admin 21 May, 2009
Hi Larry,

#1- in the JS code box:

window.addEvent('domready', function() {
$('catid').addClass('required');
});


#2- I don't think this is possible anyway!

#3- maybe you add some JS code to your form to focus on some element if the post array is not empty like:

<?php 
if($_POST){
?>
window.addEvent('domready', function() {
$('elementid').focus();
});
<?php
}
?>

in the JS code box too!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
LarryD 21 May, 2009
Wow. Just goes to show what I know. I was expecting 1 and 3 to be hard.

1) I think we're on the right track. Add 'required' didn't quite do it. I tried this:
    window.addEvent('domready', function() {
    $('catid').addClass('cf_inputbox validate-selection');
    $('catid').removeClass('inputbox');
    });


That almost works. Unfortunately there is a value (of 0) for "select a category". That passes validation. If I remove that (via firebug) it works! Any idea how to get JS to remove that value? Also, is there a way to add the 'title' for the validation message?

3) Worked great. Great idea. Thanks!
GreyHead 22 May, 2009
Hi LarryD,

Set the value of the 'dummy' option to value='' (instead of value='0') then it won't have a value and will be ignored by the validation check.

Bob
LarryD 23 May, 2009
But how can I do that? The values are generated with the code:
echo JHTML::_('list.category', 'catid', '21');


Any idea how to do that in JS?

If this isn't possible I guess I can simply hard code the categories instead of automatically generating. That should work but suffer from the obvious maintenance problems.
GreyHead 23 May, 2009
Hi LarryD,

I think that you can do it in that command, the full paramtere list is
$name, $section, $active = NULL, $javascript = NULL, $order = 'ordering', $size = 1, $sel_cat = 1
and tha tlast one should turn off the 'select category' option. So try
echo JHTML::_('list.category', 'catid', '21', '', '', 'ordering', 1, 0);

Bob
LarryD 24 May, 2009
I didn't realize that was the full signature. I tried it but no luck.

Since it removes the 'Select a category' value the box defaults to the first category and also passes through validation.

No biggie. I'll either live with the inability to validate the category or hard code the categories. The 'select a category' is staring them in the face anyway. 😉

For the sake of learning something I am willing to try anything if you get any more ideas. But I am OK with moving on at this point. Thanks for all your help on this.
Max_admin 24 May, 2009
Hi LarryD,

I think "required" should do it! 🙄

try this code to fix the 0 issue :

    window.addEvent('domready', function() {
$('catid').options[0].setProperty('value', '');
    $('catid').addClass('required');
    });



Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.