Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Form module: Attributes for form fields

edited March 2017 in Bug Reports
Hi,
I am using the forms module and created a form. The form has a field of type number. Now I want to define a max value and a default value for the field. I entered max=10 default=1 in the attributes input field.

The generated code is
<input type="number" name="quantity" id="quantity" value="" class="numeric" required min="0" max="10000" data-decimal="0" data-negative="0" max=10 default=1 />

The browser only interprets the first max value with 10000. Why isn't the value replaced. And how can I pass the default value of 1 to the field?

Comments

  • edited 2:40AM
    This appears to be an issue with the Form_builder class auto assigning a default value for the min and max. In your case if you view source, you'll see 2 max and min attributes on the element I'm assuming.

    To fix, in the Form_builder::create_number() method (around lines 2732-2733), you can change the default values to NULL.

    I've pushed this change to the develop branch:
    https://github.com/daylightstudio/FUEL-CMS/commit/ad4aee3c313ec710357a91664084670bad0d1c1a
  • edited 2:40AM
    Hi,
    for max value this worked. I also had to adjust the defaults array ~10 lines above and set min to NULL there to get it working for the min value.

    The other question is now, how to set a default value as initial value when the form is rendered.
  • edited 2:40AM
    Hi,
    I think I have found another bug?
    In line ~14 of the file forms/controllers/form.php the method $form->get_return_url(); returns nothing. If I try to read $form->return_url the correct value is shown.
  • edited 2:40AM
    Thanks for the report. I've posted a fix for the get_return_url issue. Regarding setting an initial value, I've added an additional field labeled "Default value" in which you can set defaults that should help.
  • edited 2:40AM
    did you already push it to the dev branch?
  • edited 2:40AM
    hmmm the field doesn't appear when I edit my form in the forms module...
    still only name, label, field type, required and attribute visible
  • edited 2:40AM
    Does your fuel/modules/forms/models/Forms_model.php have that line in it?
  • edited 2:40AM
    Shame on me... uploading the changed file is a great help in solving the issue... :-(
Sign In or Register to comment.