Skip Navigation

[Resuelto] Restrict number field to entries of 1-5, single digit

This support ticket is created hace 1 año, 9 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 7 respuestas, has 3 mensajes.

Last updated by lindsayH hace 1 año, 9 meses.

Assisted by: Shane.

Autor
Mensajes
#2408531

I am trying to use the Star Rating on a Form. I've deduced that I need to use a number field to use the Star Rating block on the front end.

How do I restrict data entry on the post form to just the numbers 1, 2, 3, 4 OR 5 and to be only one character entry?

Many thanks.

#2408585

Nigel
Supporter

Languages: Inglés (English ) Español (Español )

Timezone: Europe/London (GMT+00:00)

The HTML input element provides attributes to specify type and max and min; you could update the input to specify a type of "number", a min of "1" and max of "5".

hidden link

The form uses shortcodes to generate the input field and doesn't provide a way to specify those attributes.

One alternative would be to use some JavaScript (or JQuery) to manipulate the input and set those attributes.

Another would be to use the advanced form editor. Inspect the markup of the generated form on the front end and copy and paste the relevant input into the form editor, replacing the shortcode used to generate it, and manually set the attributes as required.

#2408597

I have added the below code to the JS editor of the post form, but on the front end I can still enter an 8 (for example).

What am I doing wrong?

jQuery(document).ready(function() {
    jQuery("input[name='wpcf-star-rating']").attr({        
      "min" : 1          // substitute your own
      "max" : 5          // values (or variables) here
    });
});
#2408621

Shane
Supporter

Languages: Inglés (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Lindsay,

Can you send me a link to the form that you want to restrict the number field for ?

Thanks,
Shane

#2408627

Hi Shane, I'll need to send you login as it's under development at the moment. Can you allow me to send you confidential information? Many thanks, Lins

#2408651

Shane
Supporter

Languages: Inglés (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Lindsay,

Here are the private fields.

Thanks,
Shane

#2409301

Shane
Supporter

Languages: Inglés (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Lindsay,

This should be working now.

The problem was that there was a missing comma in your code. Here is the updated version of the code.

jQuery(document).ready(function() {
    jQuery("input[name='wpcf-star-rating']").attr({        
      "min" : 1,         // substitute your own
      "max" : 5          // values (or variables) here
    });
});


Thanks,
Shane

#2409465

Great, works perfectly.
My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.