Jump to content

Field Type Integer, don't save preference max, min with value 0 (zero)


*Most Powerful Pony!*
 Share

Recommended Posts

Would be great to know what PW version, cause I think this was already fixed long time ago?

Edit: doesn't look like, but I don't know what's about it cause there seems to be some 0 ignore in PW with textfields, if you enter 000 it doesn't get saved.

Link to comment
Share on other sites

  • 2 weeks later...

Field settings are saved in a compressed format that eliminates empty values. The value 0 is considered an empty value because it resolves to true in comparison to a blank string. So a blank string can be seen as the same thing as 0 in this case. Are you able to enter and save negative values on your page that is using this validation? If so, let me know as the validation in InputfieldInteger might need an adjustment. 

Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...

As a workaround, it’s possible to set Minimum Value to 0.1, since the field is actually an InputfieldFloat. This will allow values of 0 but no negative ones.

Edit: as a matter of fact, changing the modules used for Min and Max in InputfieldInteger.module to InputfieldInteger (seems sensible anyway?), makes it work as desired, as far as I can tell. 0 values don’t disappear when set and the validation within templates works fine as well. Maybe this change is all that’s necessary?

  • Like 1
Link to comment
Share on other sites

  • 5 years later...
20 hours ago, a-ok said:

Is there any chance in allowing a textarea field to show when the value is simply 0 ?

Similar topic: 

So I guess it's not supported by the core.

But it's not difficult to write your own custom JS to show/hide the field:

$(document).ready(function() {

    // Show/hide a field if another field's value is zero
    function showHideField() {
        $('#wrap_Inputfield_my_textarea_field').toggle($('input[name="my_integer_field"]').val() === '0');
    }

    // Show/hide on DOM ready
    showHideField();
    // Show/hide on input change
    $(document).on('change', 'input[name="my_integer_field"]', showHideField);

});

You'll need to get clever with the jQuery selectors if you are using fields inside a Repeater.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...