@onehat/ui 0.3.107 → 0.3.110

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/ui",
3
- "version": "0.3.107",
3
+ "version": "0.3.110",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -127,6 +127,7 @@ function Form(props) {
127
127
  [containerWidth, setContainerWidth] = useState(),
128
128
  initialValues = _.merge(startingValues, (record && !record.isDestroyed ? record.submitValues : {})),
129
129
  defaultValues = isMultiple ? getNullFieldValues(initialValues, Repository) : initialValues, // when multiple entities, set all default values to null
130
+ validatorToUse = validator || (isMultiple ? disableRequiredYupFields(Repository?.schema?.model?.validator) : Repository?.schema?.model?.validator) || yup.object(),
130
131
  {
131
132
  control,
132
133
  formState,
@@ -142,7 +143,7 @@ function Form(props) {
142
143
  // setFocus,
143
144
  getValues: formGetValues,
144
145
  // getFieldState,
145
- // trigger,
146
+ trigger,
146
147
  } = useForm({
147
148
  mode: 'onChange', // onChange | onBlur | onSubmit | onTouched | all
148
149
  // reValidateMode: 'onChange', // onChange | onBlur | onSubmit
@@ -157,7 +158,7 @@ function Form(props) {
157
158
  // delayError: 0,
158
159
  // shouldUnregister: false,
159
160
  // shouldUseNativeValidation: false,
160
- resolver: yupResolver(validator || (isMultiple ? disableRequiredYupFields(Repository?.schema?.model?.validator) : Repository?.schema?.model?.validator) || yup.object()),
161
+ resolver: yupResolver(validatorToUse),
161
162
  context: { isPhantom },
162
163
  }),
163
164
  buildFromColumnsConfig = () => {
@@ -297,6 +298,7 @@ function Form(props) {
297
298
  useSelectorId = false,
298
299
  isHidden = false,
299
300
  getDynamicProps,
301
+ getIsRequired,
300
302
  ...propsToPass
301
303
  } = item,
302
304
  editorTypeProps = {};
@@ -384,7 +386,17 @@ function Form(props) {
384
386
  }
385
387
 
386
388
  if (isEditorViewOnly || !isEditable) {
387
- const value = (record && record[name]) || (startingValues && startingValues[name]) || null;
389
+ let value = null;
390
+ if (record?.properties && record.properties[name]) {
391
+ value = record.properties[name].displayValue;
392
+ }
393
+ if (_.isNil(value) && record && record[name]) {
394
+ value = record[name];
395
+ }
396
+ if (_.isNil(value) && startingValues && startingValues[name]) {
397
+ value = startingValues[name];
398
+ }
399
+
388
400
  let element = <Element
389
401
  value={value}
390
402
  parent={self}
@@ -473,7 +485,7 @@ function Form(props) {
473
485
  }
474
486
  onChange(newValue);
475
487
  if (onEditorChange) {
476
- onEditorChange(newValue, formSetValue, formGetValues, formState);
488
+ onEditorChange(newValue, formSetValue, formGetValues, formState, trigger);
477
489
  }
478
490
  }}
479
491
  onBlur={onBlur}
@@ -511,11 +523,11 @@ function Form(props) {
511
523
 
512
524
  let isRequired = false,
513
525
  requiredIndicator = null;
514
- if (editorType === EDITOR_TYPE__PLAIN) {
526
+ if (getIsRequired) {
527
+ isRequired = getIsRequired(formGetValues, formState);
528
+ } else if (validatorToUse?.fields && validatorToUse.fields[name]?.exclusiveTests?.required) {
515
529
  // submitted validator
516
- if (validator?.fields && validator.fields[name]?.exclusiveTests?.required) {
517
- isRequired = true;
518
- }
530
+ isRequired = true;
519
531
  } else if ((propertyDef?.validator?.spec && !propertyDef.validator.spec.optional) ||
520
532
  (propertyDef?.requiredIfPhantom && isPhantom) ||
521
533
  (propertyDef?.requiredIfNotPhantom && !isPhantom)) {