aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/javascript/helpers/CustomFieldsInputs.js4
-rw-r--r--app/models/custom_field.rb19
2 files changed, 18 insertions, 5 deletions
diff --git a/app/javascript/helpers/CustomFieldsInputs.js b/app/javascript/helpers/CustomFieldsInputs.js
index 93611538e..5240a9649 100644
--- a/app/javascript/helpers/CustomFieldsInputs.js
+++ b/app/javascript/helpers/CustomFieldsInputs.js
@@ -18,9 +18,11 @@ export default class CustomFieldsInputs extends Component {
}
listInput(cf){
+ let keys = _.orderBy(_.keys(this.options(cf).list_values), function(i){ return parseInt(i)})
return(
<Select2
- data={_.map(this.options(cf).list_values, (v, k) => {
+ data={_.map(keys, (k) => {
+ let v = this.options(cf).list_values[k]
return {id: k, text: (v.length > 0 ? v : '\u00A0')}
})}
ref={'custom_fields.' + cf.code}
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index deb0326f8..7fb45ffa0 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -158,12 +158,23 @@ class CustomField < ApplicationModel
end
class List < Integer
+ def collection_is_a_hash?
+ options["list_values"].is_a?(Hash)
+ end
+
def validate
- super
return unless value.present?
- unless value >= 0 && value < options["list_values"].size
- @owner.errors.add errors_key, "'#{@raw_value}' is not a valid value"
- @valid = false
+ if collection_is_a_hash?
+ unless options["list_values"].include(value.to_s)
+ @owner.errors.add errors_key, "'#{@raw_value}' is not a valid value"
+ @valid = false
+ end
+ else
+ super
+ unless value >= 0 && value < options["list_values"].size
+ @owner.errors.add errors_key, "'#{@raw_value}' is not a valid value"
+ @valid = false
+ end
end
end