UNPKG

@modular-forms/qwik

Version:

The modular and type-safe form library for Qwik

24 lines (23 loc) 808 B
import { initializeFieldStore, updateFieldDirty, validateIfRequired, } from '../utils'; export function setValue(form, name, value, { shouldTouched = true, shouldDirty = true, shouldValidate = true, shouldFocus = true, } = {}) { // Initialize store of specified field const field = initializeFieldStore(form, name); // Set new value field.value = value; // Update touched if set to "true" if (shouldTouched) { field.touched = true; form.touched = true; } // Update dirty if set to "true" if (shouldDirty) { updateFieldDirty(form, field); } // Validate if set to "true" and necessary if (shouldValidate) { validateIfRequired(form, field, name, { on: ['touched', 'input'], shouldFocus, }); } }