• Resolved Anonymous User 20948376

    (@anonymized-20948376)


    The input element type ‘number’ does have min and max values. Requesting support for the ‘step’ attribute as well. E.g. if I want the user to have a minimum value of 100 and a max of 500, but change the value by step of 100, so – 100, 200, 300, 400, or 500.

    Just for reference – https://ibb.co/r5msXSP

    • This topic was modified 7 months, 3 weeks ago by Anonymous User 20948376.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @abhishek0088

    I hope you’re well today!

    For values between 0 – 100 you could use slider for that instead of the number as it already has a “step” setting and aside from the look/use on front-end, it behaves the same as number (in submission, calculations, conditional logic etc).

    The “number” field does not have a step setting currently so it would require a bit of additional custom code to achieve it.

    Here is the code:

    <?php 
    
    add_action( 'forminator_before_form_render', 'wpmudev_number_field_step_form', 10, 5 );
    function wpmudev_number_field_step_form( $id, $form_type, $post_id, $form_fields, $form_settings ) {
    	if ( 123 == $id ) {
    		add_filter( 'forminator_field_number_markup', 'wpmudev_add_step_number_field', 10, 5 );
    	}
    }
    
    function wpmudev_add_step_number_field( $html, $id, $required, $placeholder, $value ) {
    	$field_id = 'number-1';
    	if ( strpos( $id, 'forminator-field-'.$field_id ) !== false ) {
    		$html = str_replace( 'name="'.$field_id.'"', 'name="'.$field_id.'" step="5"', $html );
    	}
    	
    	return $html;
    }

    And here’s how to apply it to the site:

    1. create an empty file with a .php extension (e.g. “forminator-number-step.php”) in the “/wp-content/mu-plugins” folder of your site’s WordPress install

    2. copy and paste that code into it

    3. make following adjustments in the code

    a) in this line

    if ( 123 == $id ) {

    replace the 123 number with an ID of your form (form ID is the number you see in form’s shortcode)

    b) in this line

    $field_id = 'number-1';

    adjust field ID if it’s different than number-1

    c) and in this line

    $html = str_replace( 'name="'.$field_id.'"', 'name="'.$field_id.'" step="5"', $html );

    change 5 to the value of the step (following your example, it would be 100).

    4. save the file.

    Note: make sure to set the default value for the number field also, otherwise the first “step” may be just 1 instead of the set value. So if you want e.g. min value to be stoo and step of 100, then set step=100 in code, set min value in number field to 100 and set default value of the number field to 100 as well.

    Best regards,
    Adam

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @abhishek0088

    We haven’t heard from you in a while, I’ll go and mark this thread as resolved. If you have any additional questions or require further help, please let us know!

    Kind Regards,
    Kris

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Feature Request] Add ‘step’ to number field’ is closed to new replies.