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.

select2 reset value

edited January 8 in Feature Requests
Hi!
I'm using the "select2" type of field for several fields in my form.
Everything works as expected, but once a value is selected and saved i cannot "empty" or reset the value anymore.
I get an "Add" and a "Edit" buttons beside the dropdown, but I need a "reset" button too.
Those fields are not required.

Any help?
How can i do this?

Comments

  • edited 6:28PM
    Normally, you'd edit the list of items such that you had a blank one with an empty value?
  • edited 6:28PM
    There is a "first_option" parameter you can pass to your form field that will give you that empty option.
  • edited 6:28PM
    Thank you for your answers!
    I don't want to add a "no value" record to the table.
    I used the "first_option" parameter, as suggested by admin, but i had to implement the "on_before_save" function to replace the "0" value to NULL. Otherwise, the "0" is saved.

    $fields['lugar_nacimiento_provincia_id']['first_option'] = array(0=>' ');

    Is there a better way to do that in order to avoid the on_before_save changes?

    Thanks!!
  • edited 6:28PM
    Actually, you can just use:
    $fields['lugar_nacimiento_provincia_id']['first_option'] = 'Select one...';
  • edited 6:28PM
    It saves "0" too instead of NULL value.
  • edited 6:28PM
    If you look at the options on your select, is there a 0 value for the first option or an empty value=""?
  • edited 6:28PM
    There is no value attribute for that option in the select but it keeps saving a "0".
    And no default value for that field in the db.
  • edited 6:28PM
    What type of field is it in the database? If it's an int type field, an empty string is the equivalent to a "0". If you don't want a "0" then you'll need to set the default value to NULL. You may also need to add some code in an on_before_save model hook to convert empty strings to NULL values.
    http://docs.getfuelcms.com/general/models#hooks
  • edited 6:28PM
    Everything looks ok but it keeps saving "0".
    It's OK, it's not a big problem keeping the on_before_save hooks I implemented.
    Thanks for your help!
Sign In or Register to comment.