@bpmn-io/form-js-viewer 1.7.0-alpha.0 → 1.7.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.
package/dist/index.cjs CHANGED
@@ -1851,6 +1851,10 @@ function FormField(props) {
1851
1851
  const {
1852
1852
  formId
1853
1853
  } = hooks.useContext(FormContext);
1854
+
1855
+ // track whether we should trigger initial validation on certain actions, e.g. field blur
1856
+ // disabled straight away, if viewerCommands are not available
1857
+ const [initialValidationTrigger, setInitialValidationTrigger] = hooks.useState(!!viewerCommands);
1854
1858
  const FormFieldComponent = formFields.get(field.type);
1855
1859
  if (!FormFieldComponent) {
1856
1860
  throw new Error(`cannot render field <${field.type}>`);
@@ -1864,26 +1868,47 @@ function FormField(props) {
1864
1868
 
1865
1869
  // add precedence: global readonly > form field disabled
1866
1870
  const disabled = !properties.readOnly && (properties.disabled || field.disabled || false);
1871
+
1872
+ // ensures the initial validation behavior can be re-triggered upon form reset
1873
+ hooks.useEffect(() => {
1874
+ if (!viewerCommands) {
1875
+ return;
1876
+ }
1877
+ const resetValidation = () => {
1878
+ setInitialValidationTrigger(true);
1879
+ };
1880
+ eventBus.on('import.done', resetValidation);
1881
+ eventBus.on('reset', resetValidation);
1882
+ return () => {
1883
+ eventBus.off('import.done', resetValidation);
1884
+ eventBus.off('reset', resetValidation);
1885
+ };
1886
+ }, [eventBus, viewerCommands]);
1887
+ hooks.useEffect(() => {
1888
+ if (initialValidationTrigger && initialValue) {
1889
+ setInitialValidationTrigger(false);
1890
+ viewerCommands.updateFieldValidation(field, initialValue, indexes);
1891
+ }
1892
+ }, [viewerCommands, field, initialValue, initialValidationTrigger, indexes]);
1867
1893
  const onBlur = hooks.useCallback(() => {
1868
- if (viewerCommands) {
1894
+ if (initialValidationTrigger) {
1895
+ setInitialValidationTrigger(false);
1869
1896
  viewerCommands.updateFieldValidation(field, value, indexes);
1870
1897
  }
1871
1898
  eventBus.fire('formField.blur', {
1872
1899
  formField: field
1873
1900
  });
1874
- }, [eventBus, viewerCommands, field, value, indexes]);
1901
+ }, [eventBus, field, indexes, value, viewerCommands, initialValidationTrigger]);
1875
1902
  const onFocus = hooks.useCallback(() => {
1876
1903
  eventBus.fire('formField.focus', {
1877
1904
  formField: field
1878
1905
  });
1879
1906
  }, [eventBus, field]);
1880
- hooks.useEffect(() => {
1881
- if (viewerCommands && initialValue) {
1882
- viewerCommands.updateFieldValidation(field, initialValue, indexes);
1883
- }
1884
- }, [viewerCommands, field, initialValue, indexes]);
1885
1907
  const hidden = useCondition(field.conditional && field.conditional.hide || null);
1886
1908
  const onChangeIndexed = hooks.useCallback(update => {
1909
+ // any data change will trigger validation
1910
+ setInitialValidationTrigger(false);
1911
+
1887
1912
  // add indexes of the keyed field to the update, if any
1888
1913
  onChange(FormFieldComponent.config.keyed ? {
1889
1914
  ...update,
@@ -4942,7 +4967,7 @@ function Textarea(props) {
4942
4967
  required
4943
4968
  } = validate;
4944
4969
  const textareaRef = hooks.useRef();
4945
- const [onInputChange, flushOnChange] = useFlushDebounce(({
4970
+ const [onChange, flushOnChange] = useFlushDebounce(({
4946
4971
  target
4947
4972
  }) => {
4948
4973
  props.onChange({
@@ -4957,6 +4982,12 @@ function Textarea(props) {
4957
4982
  const onInputFocus = () => {
4958
4983
  onFocus && onFocus();
4959
4984
  };
4985
+ const onInputChange = event => {
4986
+ onChange({
4987
+ target: event.target
4988
+ });
4989
+ autoSizeTextarea(textareaRef.current);
4990
+ };
4960
4991
  hooks.useLayoutEffect(() => {
4961
4992
  autoSizeTextarea(textareaRef.current);
4962
4993
  }, [value]);
@@ -8112,10 +8143,10 @@ class Form {
8112
8143
  }
8113
8144
  }
8114
8145
  clear() {
8115
- // clear form services
8146
+ // clear diagram services (e.g. EventBus)
8116
8147
  this._emit('diagram.clear');
8117
8148
 
8118
- // clear diagram services (e.g. EventBus)
8149
+ // clear form services
8119
8150
  this._emit('form.clear');
8120
8151
  }
8121
8152