validatejs not working with constraints
I am using v0.12.0.
My formValues are:
{ used_car_area_id:"", used_car_car_condition:"", used_car_car_make_id:"", used_car_car_model_id:"", used_car_car_version_id:"", used_car_city_id:"", used_car_description:"", used_car_km_driven:"", used_car_price:"", used_car_year:"" }
My constraints are:
{
used_car_car_condition: {presence: {message: "Please select car condition to proceed"}},
used_car_car_make_id: {presence: {message: "Please select a car make to proceed"} }
used_car_car_model_id: {presence: {message: "Please select a car model to proceed"} },
used_car_city_id: {presence: {message: "Please select the city where your car is located to proceed"} },
used_car_description: { length: {minimum: 10, maximum: 9999, message: "Please enter a valid description of your car"}, {presence: {message: "Please enter a valid description of your car"} }.
used_car_km_driven: { length: {minimum: 1, maximum: 7, message: "Please enter a valid mileage for the car"}, numericality: {onlyInteger: true, greaterThanOrEqualTo: 0, message: "Please enter a valid mileage for the car"}, {presence: {message: "Please enter a valid mileage for the car"} },
used_car_price: { length: {minimum: 1, maximum: 9, message: "Please enter a valid price for the car"}, numericality: {onlyInteger: true, greaterThan: 0, message: "Please enter a valid price for the car"}, {presence: {message: "Please enter a valid price for the car"} },
used_car_year: { presence: {message: "Please select a car model year to proceed"} }
}
and I am calling in this way:
var errors = validate(formValues, constraints, {fullMessages: false})
and I am getting error for this only:
{used_car_description: ["Please enter a valid description of your car"]
used_car_km_driven: ["Please enter a valid mileage for the car"]
used_car_price: ["Please enter a valid price for the car"]}
This is wrong. I should be getting all errors for used_car_car_condition, used_car_car_make_id, used_car_car_model_id, used_car_city_id, used_car_year
What am I doing wrong here?
I just read the Presence validator documentation: http://validatejs.org/#validators-presence
It seems you have to explicitly disallow empty strings ?
Maybe something like:
used_car_car_condition: {presence: {allowEmpty: false, message: "Please select car condition to proceed"}},