Skip to content

Releases: edmundhung/conform

v0.2.0

18 Jul 20:23
Compare
Choose a tag to compare

What's changed

Breaking changes

  • Removed the auto type casting preprocess setup on @conform-to/zod to enable full control over the form data parsing logic. (#5)
// Before:
const schema = z.object({
  number: z.number(), // '1' was casted to 1 automatically
  boolean: z.boolean(), // Only checkbox with 'on' value was supported
});

// To achieve the same behaviour now:
const schema = z.object({
  number: z.preprocess(value => typeof value !== 'undefined' ? Number(value) : undefined, z.number()) 
  boolean: z.preprocess(value => value === 'on', z.boolean()) 
});
  • The result of parse is redesigned (#13)
// New type to represent current form state
interface FormState<T> {
  value: FieldsetData<T, string>;
  error: FieldsetData<T, string>;
}

// New name of `FormResult`
interface Submission<T> {
  // `processed` is renamed to `modified` 
  state: 'accepted' | 'rejected' | 'modified';
  // Only available if state = accepted
  data: T;
  // This will be always available regardless of state
  form: FormState<T>;
}
// Example usage
let action = async ({ request }) => {
  const formData = await request.formData();
  const submission = parse(formData, schema);

  if (submission.state !== 'accepted') {
    return json(submission.form);
  }

  // ... do something else
};

export default function RandomForm() {
  const formState = useActionData<FormState<Schema>>();
  const formProps = useFieldset(schema, {
    defaultValue: formState.value,
    error: formState.error,
  });

  // ....
}
  • Renamed initialValue to defaultValue. This affects several places including the options on the useFieldset hook (#11)
const [fieldsetProps, { a, b, c }] = useFieldset(schema, {
  // Before:
  // initialValue: ...
  
  // Now:
  defaultValue: ...
})
  • The FieldConfig type is renamed to FieldProps with a flattened structure (#12)
// Before
export interface FieldType<T> {
  name: string;
  initialValue?: FieldsetData<T, string>;
  error?: FieldsetData<T, string>;
  form?: string;
  constraint?: Constraint;  
}

// Now
export interface FieldProps<T> extends Constraint {
  name: string;
  defaultValue?: FieldsetData<T, string>;
  error?: FieldsetData<T, string>;
  form?: string;
}

New features

  • Added new list control commands (#14)
const [fieldList, control] = useFieldList(fieldProps);

// To append a new row (New: with optional defaultValue)
<button {...control.append(defaultValue)}>Append</button>;

// To prepend a new row (New: with optional defaultValue)
<button {...control.prepend(defaultValue)}>Prepend</button>;

// New: To replace a row with another defaultValue
<button {...control.replace(index, defaultValue)}>Replace</button>;

// New: To reorder a particular row to an another index
<button {...control.reorder(fromIndex, toIndex)}>Reorder</button>;

Improvements

  • Fixed a case with error report happens before the field is re-validated (#6)
  • Error messages are now cleared properly when the form reset (#7)
  • Fixed a issue with conform.input() incorrectly ignored the multiple property (#8)
  • Improved the constraint inferred from zod schema (#9)
  • The APIs of the react adapter and zod schema resolver is now documented (#10)

Full Changelog: v0.1.1...v0.2.0

v0.1.1

07 Jul 19:28
Compare
Choose a tag to compare

What's Changed

Full Changelog: v0.1.0...v0.1.1

v0.1.0

04 Jul 10:43
Compare
Choose a tag to compare
release: bump packages version