@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.es.js CHANGED
@@ -1831,6 +1831,10 @@ function FormField(props) {
1831
1831
  const {
1832
1832
  formId
1833
1833
  } = useContext(FormContext);
1834
+
1835
+ // track whether we should trigger initial validation on certain actions, e.g. field blur
1836
+ // disabled straight away, if viewerCommands are not available
1837
+ const [initialValidationTrigger, setInitialValidationTrigger] = useState(!!viewerCommands);
1834
1838
  const FormFieldComponent = formFields.get(field.type);
1835
1839
  if (!FormFieldComponent) {
1836
1840
  throw new Error(`cannot render field <${field.type}>`);
@@ -1844,26 +1848,47 @@ function FormField(props) {
1844
1848
 
1845
1849
  // add precedence: global readonly > form field disabled
1846
1850
  const disabled = !properties.readOnly && (properties.disabled || field.disabled || false);
1851
+
1852
+ // ensures the initial validation behavior can be re-triggered upon form reset
1853
+ useEffect(() => {
1854
+ if (!viewerCommands) {
1855
+ return;
1856
+ }
1857
+ const resetValidation = () => {
1858
+ setInitialValidationTrigger(true);
1859
+ };
1860
+ eventBus.on('import.done', resetValidation);
1861
+ eventBus.on('reset', resetValidation);
1862
+ return () => {
1863
+ eventBus.off('import.done', resetValidation);
1864
+ eventBus.off('reset', resetValidation);
1865
+ };
1866
+ }, [eventBus, viewerCommands]);
1867
+ useEffect(() => {
1868
+ if (initialValidationTrigger && initialValue) {
1869
+ setInitialValidationTrigger(false);
1870
+ viewerCommands.updateFieldValidation(field, initialValue, indexes);
1871
+ }
1872
+ }, [viewerCommands, field, initialValue, initialValidationTrigger, indexes]);
1847
1873
  const onBlur = useCallback(() => {
1848
- if (viewerCommands) {
1874
+ if (initialValidationTrigger) {
1875
+ setInitialValidationTrigger(false);
1849
1876
  viewerCommands.updateFieldValidation(field, value, indexes);
1850
1877
  }
1851
1878
  eventBus.fire('formField.blur', {
1852
1879
  formField: field
1853
1880
  });
1854
- }, [eventBus, viewerCommands, field, value, indexes]);
1881
+ }, [eventBus, field, indexes, value, viewerCommands, initialValidationTrigger]);
1855
1882
  const onFocus = useCallback(() => {
1856
1883
  eventBus.fire('formField.focus', {
1857
1884
  formField: field
1858
1885
  });
1859
1886
  }, [eventBus, field]);
1860
- useEffect(() => {
1861
- if (viewerCommands && initialValue) {
1862
- viewerCommands.updateFieldValidation(field, initialValue, indexes);
1863
- }
1864
- }, [viewerCommands, field, initialValue, indexes]);
1865
1887
  const hidden = useCondition(field.conditional && field.conditional.hide || null);
1866
1888
  const onChangeIndexed = useCallback(update => {
1889
+ // any data change will trigger validation
1890
+ setInitialValidationTrigger(false);
1891
+
1867
1892
  // add indexes of the keyed field to the update, if any
1868
1893
  onChange(FormFieldComponent.config.keyed ? {
1869
1894
  ...update,
@@ -4922,7 +4947,7 @@ function Textarea(props) {
4922
4947
  required
4923
4948
  } = validate;
4924
4949
  const textareaRef = useRef();
4925
- const [onInputChange, flushOnChange] = useFlushDebounce(({
4950
+ const [onChange, flushOnChange] = useFlushDebounce(({
4926
4951
  target
4927
4952
  }) => {
4928
4953
  props.onChange({
@@ -4937,6 +4962,12 @@ function Textarea(props) {
4937
4962
  const onInputFocus = () => {
4938
4963
  onFocus && onFocus();
4939
4964
  };
4965
+ const onInputChange = event => {
4966
+ onChange({
4967
+ target: event.target
4968
+ });
4969
+ autoSizeTextarea(textareaRef.current);
4970
+ };
4940
4971
  useLayoutEffect(() => {
4941
4972
  autoSizeTextarea(textareaRef.current);
4942
4973
  }, [value]);
@@ -8092,10 +8123,10 @@ class Form {
8092
8123
  }
8093
8124
  }
8094
8125
  clear() {
8095
- // clear form services
8126
+ // clear diagram services (e.g. EventBus)
8096
8127
  this._emit('diagram.clear');
8097
8128
 
8098
- // clear diagram services (e.g. EventBus)
8129
+ // clear form services
8099
8130
  this._emit('form.clear');
8100
8131
  }
8101
8132