UNPKG

fonteva-design-guide

Version:

## Dev, Build and Test

112 lines (105 loc) 5.04 kB
({ doInit : function(component, event, helper) { // Only for field types that are not date component.set('v.type', component.get('v.type').toLowerCase()); if (component.get('v.type') !== 'date') { const inputFieldsObj = { value: component.getReference('v.value'), fieldType: component.get('v.type'), label: component.get('v.label'), isRequired: component.getReference('v.required'), fieldName: component.get('v.fieldName'), 'aura:id': component.get('v.fieldName'), id: component.get('v.fieldName'), qaData: JSON.stringify({ name: component.get('v.fieldName') + '-input', label: component.get('v.label') }), suppressValidationMessages: component.get('v.suppressValidationMessages'), fireChangeEvent: component.get('v.fireChangeEvent'), useSecondaryId: component.get('v.useSecondaryId') }; // add any additional params addObjectFields([ 'sObjectName', 'helpText', 'group', 'selectOptions', 'otherAttributes', 'styleClasses' ]); // If the boolean for secondary ID is true, add the other fields if (inputFieldsObj.useSecondaryId) { inputFieldsObj.secondaryId = component.get('v.secondaryId'); inputFieldsObj.secondaryGroup = component.get('v.secondaryGroup'); } // Setup the InputFields component params const createParams = [ ['Framework:InputFields', inputFieldsObj] ]; // Create the InputFields component and append to the document $A.createComponents(createParams, function(createdComponents, status, errors) { if (status === "SUCCESS") { component.find("frameworkInput").set("v.body", createdComponents); } }) function addObjectFields(fields) { // If the sObjectName is not provided which will enable the lookup of these attributes, add them if they are supplied. fields.forEach(function(field) { const value = component.get('v.' + field); if (value) { inputFieldsObj[field] = value; } }); } } }, validate: function(component) { if (component.get('v.type') === 'date') { // Aura exhibits strange behavior sometimes and includes additional null // references to the pfmInput fields so we must check before we validate if(component.find('pfmInput').getElement()) { // need to retrieve the pfmInput element and validate against it return component.find('pfmInput').getElement().validate(); } else { return true; } } // ensure that frameworkInput's validate() returns true or false before using it // otherwise return true if (!component.find(component.get('v.fieldName'))) { const val = component.get("v.value"); //Check if we are working with on object. if (typeof val === "object" && val !== null) { //Get the field name const fieldName = component.get("v.fieldName"); if (FH.notEmpty(fieldName)) { //Go through each property in object for (let property in val) { //If we have a match attempt the validate if found, if (property.toLowerCase() == fieldName.toLowerCase()) { if(component.find(property)){ //We have found the component, now validate it. const validated = component.find(property).validate(); return validated !== undefined ? validated:true; }else{ return false; } } } } } return true; } const validated = component.find(component.get('v.fieldName')).validate(); return validated !== undefined ? validated:true; }, pfmValueChange: function(component, evt) { const params = evt.getParams(); component.get('v.value')[params.field] = params.value; }, updateValue: function(component, event) { const arg = event.getParams().arguments; component.find(component.get('v.fieldName')).updateValue(arg.value, arg.refresh); } });