diff --git a/assets/javascripts/discourse/components/realtime-validation-settings.js.es6 b/assets/javascripts/discourse/components/realtime-validation-settings.js.es6 new file mode 100644 index 00000000..c9862978 --- /dev/null +++ b/assets/javascripts/discourse/components/realtime-validation-settings.js.es6 @@ -0,0 +1,5 @@ +import Component from "@ember/component"; + +Component.extend({ + +}); \ No newline at end of file diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index 97f003df..87b27a89 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -4,6 +4,7 @@ import { computed } from "@ember/object"; import { selectKitContent } from '../lib/wizard'; import UndoChanges from '../mixins/undo-changes'; import Component from "@ember/component"; +import wizardSchema from '../lib/wizard-schema'; export default Component.extend(UndoChanges, { componentType: 'field', @@ -26,6 +27,18 @@ export default Component.extend(UndoChanges, { showAdvanced: alias('field.type'), messageUrl: 'https://thepavilion.io/t/2809', + @discourseComputed('field.type') + validations(type) { + const applicableToField = []; + for(let validation in wizardSchema.field.validations) { + if (wizardSchema.field.validations[validation].includes(type)) { + applicableToField.push(validation); + } + } + + return applicableToField; + }, + @discourseComputed('field.type') isDateTime(type) { return ['date_time', 'date', 'time'].indexOf(type) > -1; diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 7d34a79d..36e1bb70 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -244,6 +244,10 @@ export function buildFieldTypes(types) { wizardSchema.field.types = types; } +export function buildFieldValidations(validations) { + wizardSchema.field.validations = validations; +} + if (Discourse.SiteSettings.wizard_apis_enabled) { wizardSchema.action.types.send_to_api = { api: null, diff --git a/assets/javascripts/discourse/routes/admin-wizards-wizard.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-wizard.js.es6 index 588936f8..e92e9d60 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-wizard.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-wizard.js.es6 @@ -1,5 +1,5 @@ import DiscourseRoute from "discourse/routes/discourse"; -import { buildFieldTypes } from '../lib/wizard-schema'; +import { buildFieldTypes, buildFieldValidations } from '../lib/wizard-schema'; import EmberObject, { set } from "@ember/object"; import { A } from "@ember/array"; import { all } from "rsvp"; @@ -12,7 +12,8 @@ export default DiscourseRoute.extend({ afterModel(model) { buildFieldTypes(model.field_types); - + buildFieldValidations(model.realtime_validations); + return all([ this._getThemes(model), this._getApis(model), diff --git a/assets/javascripts/discourse/templates/components/realtime-validation-settings.hbs b/assets/javascripts/discourse/templates/components/realtime-validation-settings.hbs new file mode 100644 index 00000000..2e6ee32e --- /dev/null +++ b/assets/javascripts/discourse/templates/components/realtime-validation-settings.hbs @@ -0,0 +1,15 @@ +