Skip to content

Fields Methods

Methods available on each field and form instance. Use $('path') as a shorthand for select('path').


MethodSignatureReturnsDescription
select(path)(path: string) => FieldFieldSelect a field by dot/array path. Can be chained.
$(path)(path: string) => FieldFieldAlias for select(path)
has(key)(key: string) => booleanbooleanCheck if a child field with the given key exists
container()() => Field or nullField or nullGet the parent field container, or null if root
javascript
form.$('address.city');              // via alias
form.select('members[0].firstname'); // via select()
form.$('members').$(0).$('firstname'); // chained
form.$('members').container();       // → the form itself (root)

Value Operations

MethodSignatureReturnsDescription
get()() => anyobjectGet all field data with all props and computed values
get(prop)(prop: string or string[]) => anyanyGet value of a specific prop (or an array of props)
set(val)(val: any) => voidvoidSet field value directly
set(obj)(obj: object) => voidvoidSet nested field values from an object
set(prop, val)(prop: string, val: any) => voidvoidSet a specific field property
set(prop, obj)(prop: string, obj: object) => voidvoidSet a property on nested fields from an object
update(fields)(fields: object) => voidvoidUpdate field values, auto-creating new fields as needed
add(obj)(obj?: any) => anyanyAdd a new field or nested field entry
del(key)(key: string) => voidvoidDelete a field or nested field by key or path
move(fromIndex, toIndex)(from: number, to: number) => voidvoidMove an array field item from one index to another
javascript
// Get all props
form.$('username').get();

// Set field value
form.$('username').set('newValue');

// Set a specific prop
form.$('username').set('label', 'Display Name');

// Add to nested array
form.$('members').add({ firstname: 'John', lastname: 'Doe' });

// Add to simple array
form.$('hobbies').add({ value: 'Tennis' });

// Delete by key
form.$('members').del(0);

// Move array item
form.$('members').move(0, 2);

// Update multiple values
form.update({ username: 'Jane', email: 'jane@example.com' });

Validation

MethodSignatureReturnsDescription
validate()() => PromisePromiseValidate the field and return a promise resolving to true/false
validate(path)(path: string) => PromisePromiseValidate a specific field by path
validate(opt)(opt: { related?: boolean, showErrors?: boolean }) => PromisePromiseValidate with options
validate(path, opt)(path: string, opt: object) => PromisePromiseValidate a path with options
check(prop)(prop: string) => booleanbooleanCheck a computed property on this field
check(prop, deep)(prop: string, deep: boolean) => booleanbooleanCheck a computed property, recursing into nested fields
invalidate(msg, deep?, async?)(msg: string, deep?: boolean, async?: boolean) => voidvoidMark the field as invalid with an error message
resetValidation(deep?)(deep?: boolean) => voidvoidReset validation status (clears errors, resets error stack)
javascript
// Validate field
const isValid = await form.$('email').validate();

// Validate with options
await form.$('email').validate({ related: true, showErrors: true });

// Check computed
form.$('email').check('isDirty');          // false
form.$('address').check('isValid', true);  // deep check

// Invalidate manually
form.$('email').invalidate('Custom error message');
form.$('email').invalidate('Async error', true, true);

// Reset validation
form.$('email').resetValidation(true);

Actions

MethodSignatureReturnsDescription
clear(deep?)(deep?: boolean) => voidvoidClear the field to empty value
reset(deep?)(deep?: boolean) => voidvoidReset the field to default value
submit(hooks?, opts?)(hooks?: object, opts?: object) => PromisePromiseValidate and trigger onSuccess/onError hooks
focus()() => voidvoidProgrammatically focus the field (requires ref)
blur()() => voidvoidProgrammatically blur the field (requires ref)
trim()() => voidvoidApply String.trim() to the value if it's a string
javascript
// Clear to empty
form.$('username').clear();

// Reset to default
form.$('username').reset();

// Submit a fieldset
form.$('step1').submit({
  onSuccess: (fieldset) => console.log('Step 1 valid!', fieldset.values()),
  onError:   (fieldset) => console.log('Step 1 errors:', fieldset.errors()),
});

// Focus / Blur
form.$('email').focus();
form.$('email').blur();

// Trim whitespace
form.$('username').trim();

Submit Options

OptionTypeDefaultDescription
execOnSubmitHookbooleantrueExecute the onSubmit hook before validating
execValidationHooksbooleantrueExecute onSuccess / onError hooks after validation
validatebooleantruePerform validation before calling hooks

UI & Bindings

MethodSignatureReturnsDescription
bind(props?)(props?: object) => objectobjectGet the current field bindings (template/rewriter). Sets ref automatically.
showErrors(show?, deep?)(show?: boolean, deep?: boolean) => voidvoidShow or hide error messages
javascript
// In a React component:
<input {...form.$('email').bind()} />

// With custom props:
<input {...form.$('email').bind({ className: 'my-input' })} />

// Show/hide errors
form.$('email').showErrors(true);   // display errors
form.$('email').showErrors(false);  // hide errors

MobX Events

MethodSignatureReturnsDescription
observe(opt)(opt: object) => functiondisposerDefine a MobX observer on field props or fields map
intercept(opt)(opt: object) => functiondisposerDefine a MobX interceptor on field props or fields map
dispose()() => voidvoidRemove all observers and interceptors on this field and nested fields
javascript
const disposer = form.$('email').observe({
  props: ['value', 'error'],
  callback: (change) => console.log(change),
});

// Clean up
disposer();

Helpers

Convenience methods to extract structured data from a field and its nested fields.

MethodSignatureReturnsDescription
values()() => objectobjectGet field and nested field values
errors()() => objectobjectGet field and nested field errors
labels()() => objectobjectGet field and nested field labels
placeholders()() => objectobjectGet field and nested field placeholders
defaults()() => objectobjectGet field and nested field default values
initials()() => objectobjectGet field and nested field initial values
types()() => objectobjectGet field and nested field types
javascript
form.values();
// { username: 'SteveJobs', email: 's.jobs@apple.com' }

form.$('address').values();
// { street: 'Broadway', city: 'New York' }

Iteration

MethodSignatureReturnsDescription
map(callback)(fn: (field) => any) => any[]arrayMap over nested fields
reduce(callback, acc)(fn: (acc, field) => any, init: any) => anyanyReduce nested fields
each(callback)(fn: (field) => void) => voidvoidIterate over all fields and nested fields recursively
javascript
// Get all values
form.$('members').map(field => field.value);

// Sum computed values
form.$('products').reduce((sum, field) => sum + field.value.price, 0);

// Log every field path
form.each(field => console.log(field.path));

Event Handlers

Event handlers bind to DOM events and update field state automatically. They accept a Proxy-like event object or direct value.

HandlerInputDescription
sync(e) / onChange(e)Event or anyUpdate value from DOM event (input, checkbox) or direct value
onToggle(e)Event or anyUpdate value from toggle/checkbox event (alias of sync)
onFocus(e)EventTrack focused state on focus
onBlur(e)EventTrack touched and blurred state on blur
onKeyUp(e)EventExecuted on key up
onKeyDown(e)EventExecuted on key down
onDrop(e)EventHandle file drop events when type: "file". Access files via field.files.
onSubmit(e)EventSub-form submission: validate fieldset, call onSuccess / onError
onClear(e)EventClear all fields and nested fields to empty value
onReset(e)EventReset all fields and nested fields to default value
onAdd(e)EventAdd a new field or nested field entry
onDel(e)EventDelete a field or nested field by key
javascript
// In JSX:
<input {...form.$('email').bind()} onChange={form.$('email').onChange} />

// All event handlers accept the event object:
<input
  onFocus={form.$('email').onFocus}
  onBlur={form.$('email').onBlur}
/>

// Direct value (without event):
form.$('email').onChange('new@email.com');

Released under the MIT License.