Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify max in NumberInput widget

I have a form that is using NumberInput widget to accept a rating for a Song from the user. The number should be between 0-5. My Song model has a MaxValueValidator but I want the NumberInput widget to show options only from 0-5.

like image 470
Darshan Chaudhary Avatar asked Jan 07 '23 03:01

Darshan Chaudhary


1 Answers

In your form you can add min and max value which atleast shows the user the value should be between the limits.

rating = forms.CharField(label='Rating', widget=forms.TextInput(attrs={'min':1,'max': '5','type': 'number'}))
like image 113
Suresh Jaganathan Avatar answered Jan 16 '23 02:01

Suresh Jaganathan