vanjs-jsf 0.0.19 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,23 +55,21 @@ class VanJsfForm {
55
55
  getFieldsAndValuesFromJsf(headlessForm, initialValues) {
56
56
  const fields = headlessForm.fields;
57
57
  const formValues = {};
58
- const values = { ...initialValues };
59
- console.log(values);
60
58
  const vanJsfFields = this.processFields(fields, initialValues, formValues);
61
59
  return { vanJsfFields, formValues };
62
60
  }
63
61
  handleFieldChange(field, value) {
64
- console.log(value);
65
- console.log(field.name);
66
62
  this.formValues[field.name] = value;
63
+ // For file fields, also store the selected arrayPath key
64
+ if (field.inputType === "file") {
65
+ this.formValues[field.name + "__arrayPath"] = field.arrayPathValue;
66
+ }
67
67
  this.config.formValues = this.formValues;
68
68
  const { formErrors } = this.headlessForm.handleValidation(this.formValues);
69
69
  let extraError = false;
70
- console.log("formErrors", formErrors);
71
70
  this.formFields.forEach((f) => {
72
71
  f.isVisible = f.field.isVisible;
73
72
  f.error = formErrors?.[f.name] ?? "";
74
- console.log(f.field.error);
75
73
  if (f.field.error) {
76
74
  extraError = true;
77
75
  }
@@ -106,32 +104,28 @@ export function jsform(attributes, ...children) {
106
104
  if (!attributes.schema) {
107
105
  throw new Error("JSON Schema is required");
108
106
  }
109
- let config = attributes.config;
110
- let isValid = attributes.isValid;
111
- if (!config) {
112
- config = { initialValues: {}, formValues: {} };
113
- }
114
- else if (!config.initialValues) {
107
+ const config = attributes.config ?? { initialValues: {}, formValues: {} };
108
+ if (!config.initialValues)
115
109
  config.initialValues = {};
116
- }
117
- else if (!config.formValues) {
110
+ if (!config.formValues)
118
111
  config.formValues = {};
119
- }
112
+ const isValid = attributes.isValid;
120
113
  const vanJsfForm = new VanJsfForm(attributes.schema, config, isValid);
121
- console.log(vanJsfForm);
122
114
  const fields = vanJsfForm.formFields.map((field) => field.render());
123
115
  const childrenWithFields = [...fields, ...children]; // Concatenate fields with other children
124
116
  const originalOnSubmit = attributes.onsubmit;
125
117
  const handleSubmit = (e) => {
126
118
  e.preventDefault();
127
119
  config.formValues = vanJsfForm.formValues;
128
- originalOnSubmit && originalOnSubmit(e);
120
+ if (originalOnSubmit)
121
+ originalOnSubmit(e);
129
122
  };
130
123
  const originalOnChange = attributes.onchange;
131
124
  const handleChange = (e) => {
132
125
  e.preventDefault();
133
126
  config.formValues = vanJsfForm.formValues;
134
- originalOnChange && originalOnChange(vanJsfForm, e);
127
+ if (originalOnChange)
128
+ originalOnChange(vanJsfForm, e);
135
129
  };
136
130
  attributes.onsubmit = handleSubmit;
137
131
  attributes.onchange = handleChange;