diff --git a/ayanova/devdocs/todo.txt b/ayanova/devdocs/todo.txt index 1c68da75..9f92e32c 100644 --- a/ayanova/devdocs/todo.txt +++ b/ayanova/devdocs/todo.txt @@ -49,6 +49,10 @@ CURRENT TODOs TODO: UI would be greatly enhanced if server defined form customization rules for required fields REGULAR fields only (custom are already handled) were incorporated into client end before roundtripping to the server - Right now it has to save the record to get the return errors about required regular fields, that is shit. The client is easily able to tell what is required in the form customization so it should be able to surface that up front - This will save bandwidth and annoyance factor 1000 for people + - ERROR MESSAGE: + - Currently it appears identically to the stock required but should indicate it's user required + - Need new or maybe already exists locale key for it, currently it's this: // "ErrorRequiredFieldEmpty": "{0} is a required field. Please enter a value for {0}", + TODO: Widget edit form, new record sb time and dates pre-filled in? Server involved? How to handle new record initial date set? - Seeing a few issues that are probably related to having an empty record on start of new object diff --git a/ayanova/src/api/gzform.js b/ayanova/src/api/gzform.js index 7f93a6ec..cea1e4cd 100644 --- a/ayanova/src/api/gzform.js +++ b/ayanova/src/api/gzform.js @@ -1,4 +1,4 @@ -/* XXeslint-disable */ +/* xeslint-disable */ /////////////////////////////// // gzform // @@ -342,6 +342,57 @@ export default { return err; }, /////////////////////////////// + // USER REQUIRED FIELDS + // (Fields defined by AyaNova users as required on form that are not stock required already) + // + userRequiredFields(vm, ref, userRequiredFieldName) { + if (vm.formState.loading) { + return false; + } + + var template = + window.$gz.store.state.formCustomTemplate[vm.formCustomTemplateKey]; + if (template === undefined) { + return false; + } + //See if control ref is in server required fields collection + //this is a collection of both custom field definitions and standard form fields that are required + //since all names are unique can just filter out the one we need by name which will inherently ignore custom fields by default + //_https://lodash.com/docs#find + var templateItem = window.$gz._.find(template, [ + "fld", + userRequiredFieldName + ]); + + //templateItem.required is a string value, not a boolean value + if (templateItem === undefined || templateItem.required !== "true") { + return false; + } + + var ctrl = getControl(vm, ref); + if (typeof ctrl == "undefined") { + return false; + } + + var value = getControlValue(ctrl); + if (!isEmpty(value)) { + return false; + } + + // "ErrorRequiredFieldEmpty": "{0} is a required field. Please enter a value for {0}", + var err = window.$gz.locale.get("ErrorRequiredFieldEmpty"); + var fieldName = getControlLabel(ctrl); + err = window.$gz._.replace(err, "{0}", fieldName); + //lodash replace only replaces first instance so need to do it twice + err = window.$gz._.replace(err, "{0}", fieldName); + //Update the form status + this.setFormState({ + vm: vm, + valid: false + }); + return err; + }, + /////////////////////////////// // CUSTOMFIELDS // For now the only rule is that they can be required or not // diff --git a/ayanova/src/views/inventory-widget-edit.vue b/ayanova/src/views/inventory-widget-edit.vue index f7fe4386..8321e609 100644 --- a/ayanova/src/views/inventory-widget-edit.vue +++ b/ayanova/src/views/inventory-widget-edit.vue @@ -146,6 +146,9 @@ :error-messages="form().serverErrors(this, 'notes')" ref="notes" @change="onChange('notes')" + :rules="[ + form().userRequiredFields(this, 'notes', 'WidgetNotes') + ]" auto-grow clearable >