Created a custom field “Rating” type" and I want the user can only choose an absolute count value,
For Example, A user can only choose stars 1, 2, 3, 4 and 5 and cannot choose partial count (decimal value) such as 1.2, 2.5, 3.7 etc.
I cannot find how to do that. can anyone guide me on this?
Reference screenshot for better understanding:
ejaaz
2
You can add validation in client-side scripts or server-side scripts in the validate
method to restrict selecting partial ratings.
python code
def validate(self):
if((self.rating * 10) % 2) != 0:
frappe.throw("Your Error message")
Javascript code
frappe.ui.form.on("Doctype", {
validate:function(frm){
if((frm.doc.rating * 10) % 2){
frappe.throw("Your Error message")
}
}
})
1 Like