working url and number validation
Dieser Commit ist enthalten in:
Ursprung
506a245a47
Commit
ce9373dd91
7 geänderte Dateien mit 24 neuen und 6 gelöschten Zeilen
|
@ -14,7 +14,7 @@ export default Ember.Component.extend({
|
||||||
categoryPropertyTypes: generateSelectKitContent(['id', 'slug']),
|
categoryPropertyTypes: generateSelectKitContent(['id', 'slug']),
|
||||||
|
|
||||||
@computed('field.type')
|
@computed('field.type')
|
||||||
isInput: (type) => type === 'text' || type === 'textarea',
|
isInput: (type) => type === 'text' || type === 'textarea' || type === 'url',
|
||||||
|
|
||||||
@computed('field.type')
|
@computed('field.type')
|
||||||
isCategoryOrTag: (type) => type === 'tag' || type === 'category',
|
isCategoryOrTag: (type) => type === 'tag' || type === 'category',
|
||||||
|
|
|
@ -4,7 +4,6 @@ import getUrl from 'discourse-common/lib/get-url';
|
||||||
export default StepController.extend({
|
export default StepController.extend({
|
||||||
actions: {
|
actions: {
|
||||||
goNext(response) {
|
goNext(response) {
|
||||||
debugger;
|
|
||||||
const next = this.get('step.next');
|
const next = this.get('step.next');
|
||||||
if (response.redirect_on_next) {
|
if (response.redirect_on_next) {
|
||||||
window.location.href = response.redirect_on_next;
|
window.location.href = response.redirect_on_next;
|
||||||
|
|
|
@ -214,13 +214,14 @@ export default {
|
||||||
inputComponentName: function() {
|
inputComponentName: function() {
|
||||||
const type = this.get('field.type');
|
const type = this.get('field.type');
|
||||||
const id = this.get('field.id');
|
const id = this.get('field.id');
|
||||||
if (type === 'text-only') return false;
|
if (['text-only'].includes(type)) return false;
|
||||||
return (type === 'component') ? Ember.String.dasherize(id) : `wizard-field-${type}`;
|
return (type === 'component') ? Ember.String.dasherize(id) : `wizard-field-${type}`;
|
||||||
}.property('field.type', 'field.id')
|
}.property('field.type', 'field.id')
|
||||||
});
|
});
|
||||||
|
|
||||||
const StandardFieldValidation = [
|
const StandardFieldValidation = [
|
||||||
'text',
|
'text',
|
||||||
|
'number',
|
||||||
'textarea',
|
'textarea',
|
||||||
'dropdown',
|
'dropdown',
|
||||||
'tag',
|
'tag',
|
||||||
|
@ -259,6 +260,8 @@ export default {
|
||||||
valid = val && val.id > 0;
|
valid = val && val.id > 0;
|
||||||
} else if (StandardFieldValidation.indexOf(type) > -1) {
|
} else if (StandardFieldValidation.indexOf(type) > -1) {
|
||||||
valid = val && val.length > 0;
|
valid = val && val.length > 0;
|
||||||
|
} else if (type === 'url') {
|
||||||
|
valid = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{{input type='text' id=field.id value=field.value}}
|
|
@ -9,6 +9,7 @@ en:
|
||||||
field:
|
field:
|
||||||
too_short: "%{label} must be at least %{min} characters"
|
too_short: "%{label} must be at least %{min} characters"
|
||||||
required: "%{label} is required."
|
required: "%{label} is required."
|
||||||
|
not_url: "%{label} must be a valid url"
|
||||||
none: "We couldn't find a wizard at that address."
|
none: "We couldn't find a wizard at that address."
|
||||||
no_skip: "Wizard can't be skipped"
|
no_skip: "Wizard can't be skipped"
|
||||||
export:
|
export:
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'uri'
|
||||||
|
|
||||||
TagStruct = Struct.new(:id, :name)
|
TagStruct = Struct.new(:id, :name)
|
||||||
|
|
||||||
class CustomWizard::Builder
|
class CustomWizard::Builder
|
||||||
|
@ -330,7 +332,6 @@ class CustomWizard::Builder
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_field(field, updater, step_template)
|
def validate_field(field, updater, step_template)
|
||||||
byebug
|
|
||||||
value = updater.fields[field['id']]
|
value = updater.fields[field['id']]
|
||||||
min_length = false
|
min_length = false
|
||||||
label = field['label'] || I18n.t("#{field['key']}.label")
|
label = field['label'] || I18n.t("#{field['key']}.label")
|
||||||
|
@ -347,6 +348,12 @@ class CustomWizard::Builder
|
||||||
updater.errors.add(field['id'].to_s, I18n.t('wizard.field.too_short', label: label, min: min_length.to_i))
|
updater.errors.add(field['id'].to_s, I18n.t('wizard.field.too_short', label: label, min: min_length.to_i))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if is_url_type(field)
|
||||||
|
if !check_if_url(value)
|
||||||
|
updater.errors.add(field['id'].to_s, I18n.t('wizard.field.not_url', label: label))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
## ensure all checkboxes are booleans
|
## ensure all checkboxes are booleans
|
||||||
if field['type'] === 'checkbox'
|
if field['type'] === 'checkbox'
|
||||||
updater.fields[field['id']] = standardise_boolean(value)
|
updater.fields[field['id']] = standardise_boolean(value)
|
||||||
|
@ -357,13 +364,20 @@ class CustomWizard::Builder
|
||||||
validator[:block].call(field, updater, step_template)
|
validator[:block].call(field, updater, step_template)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
byebug
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_text_type(field)
|
def is_text_type(field)
|
||||||
['text', 'textarea'].include? field['type']
|
['text', 'textarea'].include? field['type']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_url_type(field)
|
||||||
|
['url'].include? field['type']
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_if_url(value)
|
||||||
|
value =~ URI::regexp
|
||||||
|
end
|
||||||
|
|
||||||
def standardise_boolean(value)
|
def standardise_boolean(value)
|
||||||
ActiveRecord::Type::Boolean.new.cast(value)
|
ActiveRecord::Type::Boolean.new.cast(value)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class CustomWizard::Field
|
class CustomWizard::Field
|
||||||
def self.types
|
def self.types
|
||||||
@types ||= ['checkbox', 'composer', 'dropdown', 'tag', 'category', 'image', 'text', 'textarea', 'text-only', 'number', 'upload', 'user-selector']
|
@types ||= ['checkbox', 'composer', 'dropdown', 'tag', 'category', 'image', 'text', 'textarea', 'text-only', 'number', 'upload', 'user-selector', 'url']
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.require_assets
|
def self.require_assets
|
||||||
|
|
Laden …
In neuem Issue referenzieren