Everything You Need to Know

Forms & Validation


Truck Chassis

Forms are complicated. You need to validate different inputs for values before submitting. And maybe you need to make a JSON object to send to the server. Truck's Form does all of this for you. It validates and converts your form data into a JSON object.

To validate your form, you use $.Form. This takes and array of elements to validate. Each item has a selector for the element, the type of validation to run and optionally a callback that will execute when validation fails. You can use this to notify the user that their input for the element was wrong.

Form adds the class `invalid` on inputs that fail validation. Truck has styles that puts a red glow around invalid inputs. You can define a new style for the class in your app to change the look of invalid inputs. Similarly, Truck puts the class `valid` on inputs that pass validation. This has no default styling, but you can define one your self in your apps stylesheet.