Format number field

Support General Format number field

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #40643
    Kyle IversonKyle Iverson
    Participant

    Hi,

    The sanitize callback on the number field has been set to price_format. I've also set the step to any.

    function price_format( $value, $field, $old_value, $object_id ) {
    $value = number_format( $value, 2, ',', ' ' );
    return $value;
    }

    When entering a number into the field and saving the post, it displays fine on the front-end, but the field value disappears in the back-end.

    E.g. If I enter any number between 1 and 999, the field updates to 1,00 or 999,00. Any number over that and the field is blank after saving.

    #40649
    PeterPeter
    Moderator

    Hello,

    That is expected behavior. The number field only displays the raw number without formatting. You can format the number on the frontend only, don't use the sanitize callback function to modify the value format.

    Or use a custom field type Multimask which is developed by an expert Meta Box user https://github.com/badabingbreda/field-text-multimask

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.