Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <aura:component controller="ltngController"
- implements="forceCommunity:availableForAllPageTypes">
- <aura:attribute name="userId" type="String" />
- <aura:attribute name="contact" type="Contact"/>
- <aura:attribute name="fieldSetName" type="String"/>
- <aura:attribute name="fields" type="Object[]"/>
- <aura:attribute name="picklistValues" type="Object[]" />
- <aura:attribute name="form" type="Aura.Component[]"/>
- <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
- <!--HTML and other Lightning components-->
- <div class="row">
- <div class="section">
- <div class="cell form">
- {!v.form}
- </div>
- </div>
- </div></aura:component>
- createForm2 : function(cmp) {
- var fields = cmp.get('v.fields');
- var obj = cmp.get('v.contact');
- for (var i = 0; i < fields.length; i++) {
- var field = fields[i];
- if (field.type != 'PICKLIST'){
- var picklistValues = cmp.get("v.picklistValues");
- // create the inputSelect component and add to the form component
- $A.createComponent("ui:inputSelect",
- {"aura:id":field.label,"label":field.label,
- "required":field.required,"value":obj[field.fieldpath]
- },
- function(newSelect){
- if (newSelect.isValid()){
- var form = cmp.get("v.form");
- form.push(newSelect);
- cmp.set("v.form",form);
- }
- }
- );
- var options = []; // to hold new options in an array
- for (var j = 0; j < picklistValues.length; j++){
- var pItem = picklistValues[j];
- // picklist field matches current field, create option
- if (pItem.fieldName == field.fieldPath){
- $A.createComponent("ui:inputSelectOption",
- {"label":pItem.ItemLabel, "text":pItem.ItemValue
- },
- function(newOption){
- if (obj[field.fieldPath] == pItem.ItemValue){
- newOption.set("v.value",true);
- options.push(newOption);
- // using cmp.find("<inputSelect aura:id>") doesn't work!!
- form[form.length - 1].set("v.body",options);
- // also tried setting "v.options" - same result
- form[form.length-1].set("v.value", pItem.ItemValue);
- cmp.set("v.form",form);
- } else {
- newOption.set("v.value",false);
- options.push(newOption);
- form[form.length - 1].set("v.body",options);
- cmp.set("v.form",form);
- }
- }
- );
- }
- }
- }
- }
- <div data-aura-rendered-by="442:0" class="uiInput uiInputSelect uiInput--default uiInput--select" data-aura-class="uiInput uiInputSelect uiInput--default uiInput--select">
- <label class="uiLabel-left form-element__label uiLabel" for="9:114;a" data-aura-rendered-by="437:0" data-aura-class="uiLabel">
- <span class="" data-aura-rendered-by="438:0">Gender</span>
- <!--render facet: 440:0-->
- <!--render facet: 441:0-->
- </label>
- <select class=" select" size="1" aria-describedby="" id="9:114;a" data-aura-rendered-by="14:114;a" data-interactive-lib-uid="4">
- <!--render facet: 15:114;a-->
- <option label="" value="undefined"></option>
- <option label="" value="undefined"></option>
- </select>
Add Comment
Please, Sign In to add comment