Add Object Oriented Forms
to your JavaScript apps:
// Create a Form instance
const form = new Form({
name: '',
description: ''
});
// Submit a form
form.post('/endpoint')
.then(response => alert('done!'))
.catch(e => alert('error'));
// Reset the form data
form.reset();
// Get data
form.data();
// Get errors
erros = form.errors;
// Get error by key-name
form.errors.get('key');
// Record errors
let errors = {};
form.errors.record(errors);
// Clear
form.errors.clear();
// Check if has errors
form.errors.any();
To learn more about, visit Laracasts:
- Learn Vue 2: Step By Step: Object-Oriented Forms: Part 1
- Learn Vue 2: Step By Step: Object-Oriented Forms: Part 2
- Learn Vue 2: Step By Step: Object-Oriented Forms: Part 3
You can find the original source code here: https://github.com/laracasts/Vue-Forms/blob/master/public/js/app.js