LT-67: Creating default custom validatior for empty strings
This commit is contained in:
parent
e5eb98cbc0
commit
a057243745
@ -6,7 +6,8 @@
|
|||||||
{{>inputText labelClass='form-group' key='name'}}
|
{{>inputText labelClass='form-group' key='name'}}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
{{>inputSelect labelClass='form-group' key='type' hideSearch=true
|
{{>inputSelect labelClass='form-group' key='type'
|
||||||
|
hideSearch=true disabled=(eq this.mode.get 'edit')
|
||||||
options=(clone placeholder='Choose a server type...')}}
|
options=(clone placeholder='Choose a server type...')}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,5 +1,27 @@
|
|||||||
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
|
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
|
||||||
|
|
||||||
|
/*
|
||||||
|
Extend the available options on schema definitions:
|
||||||
|
|
||||||
|
* valuesLabels: Used in conjunction with allowedValues to define the text
|
||||||
|
label for each value (used on forms)
|
||||||
|
|
||||||
|
* textOptional: Used to allow empty strings
|
||||||
|
|
||||||
|
*/
|
||||||
SimpleSchema.extendOptions({
|
SimpleSchema.extendOptions({
|
||||||
valuesLabels: Match.Optional([String])
|
valuesLabels: Match.Optional([String]),
|
||||||
|
textOptional: Match.Optional(Boolean)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add default required validation for empty strings which can be bypassed
|
||||||
|
// using textOptional=true definition
|
||||||
|
SimpleSchema.addValidator(function() {
|
||||||
|
if (
|
||||||
|
this.definition.optional !== true &&
|
||||||
|
this.definition.textOptional !== true &&
|
||||||
|
this.value === ''
|
||||||
|
) {
|
||||||
|
return 'required';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -30,23 +30,43 @@ OHIF.mixins.group = new OHIF.Mixin({
|
|||||||
component.value = value => {
|
component.value = value => {
|
||||||
const isGet = _.isUndefined(value);
|
const isGet = _.isUndefined(value);
|
||||||
const isArray = instance.data.arrayValues;
|
const isArray = instance.data.arrayValues;
|
||||||
|
|
||||||
|
// Create the result data as array or object
|
||||||
const result = isArray ? [] : {};
|
const result = isArray ? [] : {};
|
||||||
|
|
||||||
|
// Get the group current value and return it
|
||||||
if (isGet) {
|
if (isGet) {
|
||||||
|
// Iterate over each registered item and extract its value
|
||||||
component.registeredItems.forEach(child => {
|
component.registeredItems.forEach(child => {
|
||||||
if (!isArray) {
|
// Check if it is an array or an object group
|
||||||
|
if (isArray) {
|
||||||
|
// Push the item value to the result array
|
||||||
|
result.push(child.value());
|
||||||
|
} else {
|
||||||
|
// Get the item key
|
||||||
const key = child.templateInstance.data.key;
|
const key = child.templateInstance.data.key;
|
||||||
|
|
||||||
|
//Check if a key is set for the item
|
||||||
if (key) {
|
if (key) {
|
||||||
|
// Add the item value to the result object
|
||||||
result[key] = child.value();
|
result[key] = child.value();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
result.push(child.value());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Return the resulting data as array or object
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the group current value
|
||||||
const groupValue = typeof value === 'object' ? value : result;
|
const groupValue = typeof value === 'object' ? value : result;
|
||||||
|
|
||||||
|
// Stop here if there is no value defined for this group
|
||||||
|
if (!groupValue) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate over each registered item and set its value
|
||||||
let i = 0;
|
let i = 0;
|
||||||
component.registeredItems.forEach(child => {
|
component.registeredItems.forEach(child => {
|
||||||
const key = isArray ? i : child.templateInstance.data.key;
|
const key = isArray ? i : child.templateInstance.data.key;
|
||||||
@ -54,6 +74,8 @@ OHIF.mixins.group = new OHIF.Mixin({
|
|||||||
child.value(childValue);
|
child.value(childValue);
|
||||||
i++;
|
i++;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Trigger the change event after setting the new value
|
||||||
component.$element.trigger('change');
|
component.$element.trigger('change');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
class="{{this.class}}"
|
class="{{this.class}}"
|
||||||
name="{{this.name}}"
|
name="{{this.name}}"
|
||||||
multiple="{{#if this.multiple}}multiple{{/if}}"
|
multiple="{{#if this.multiple}}multiple{{/if}}"
|
||||||
|
disabled="{{#if this.disabled}}disabled{{/if}}"
|
||||||
data-key="{{this.key}}"
|
data-key="{{this.key}}"
|
||||||
{{this.tagAttributes}}
|
{{this.tagAttributes}}
|
||||||
>
|
>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user