Guest User

Untitled

a guest
Oct 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. <aura:component controller="ltngController"
  2. implements="forceCommunity:availableForAllPageTypes">
  3. <aura:attribute name="userId" type="String" />
  4. <aura:attribute name="contact" type="Contact"/>
  5. <aura:attribute name="fieldSetName" type="String"/>
  6. <aura:attribute name="fields" type="Object[]"/>
  7. <aura:attribute name="picklistValues" type="Object[]" />
  8.  
  9. <aura:attribute name="form" type="Aura.Component[]"/>
  10. <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
  11. <!--HTML and other Lightning components-->
  12. <div class="row">
  13. <div class="section">
  14. <div class="cell form">
  15. {!v.form}
  16. </div>
  17. </div>
  18. </div></aura:component>
  19.  
  20. createForm2 : function(cmp) {
  21. var fields = cmp.get('v.fields');
  22. var obj = cmp.get('v.contact');
  23. for (var i = 0; i < fields.length; i++) {
  24. var field = fields[i];
  25.  
  26. if (field.type != 'PICKLIST'){
  27. var picklistValues = cmp.get("v.picklistValues");
  28.  
  29. // create the inputSelect component and add to the form component
  30. $A.createComponent("ui:inputSelect",
  31. {"aura:id":field.label,"label":field.label,
  32. "required":field.required,"value":obj[field.fieldpath]
  33. },
  34. function(newSelect){
  35. if (newSelect.isValid()){
  36. var form = cmp.get("v.form");
  37. form.push(newSelect);
  38. cmp.set("v.form",form);
  39. }
  40. }
  41. );
  42.  
  43. var options = []; // to hold new options in an array
  44. for (var j = 0; j < picklistValues.length; j++){
  45. var pItem = picklistValues[j];
  46.  
  47. // picklist field matches current field, create option
  48. if (pItem.fieldName == field.fieldPath){
  49. $A.createComponent("ui:inputSelectOption",
  50. {"label":pItem.ItemLabel, "text":pItem.ItemValue
  51. },
  52. function(newOption){
  53. if (obj[field.fieldPath] == pItem.ItemValue){
  54. newOption.set("v.value",true);
  55. options.push(newOption);
  56.  
  57. // using cmp.find("<inputSelect aura:id>") doesn't work!!
  58. form[form.length - 1].set("v.body",options);
  59. // also tried setting "v.options" - same result
  60.  
  61. form[form.length-1].set("v.value", pItem.ItemValue);
  62. cmp.set("v.form",form);
  63. } else {
  64. newOption.set("v.value",false);
  65. options.push(newOption);
  66. form[form.length - 1].set("v.body",options);
  67. cmp.set("v.form",form);
  68. }
  69. }
  70. );
  71. }
  72. }
  73. }
  74. }
  75.  
  76. <div data-aura-rendered-by="442:0" class="uiInput uiInputSelect uiInput--default uiInput--select" data-aura-class="uiInput uiInputSelect uiInput--default uiInput--select">
  77. <label class="uiLabel-left form-element__label uiLabel" for="9:114;a" data-aura-rendered-by="437:0" data-aura-class="uiLabel">
  78. <span class="" data-aura-rendered-by="438:0">Gender</span>
  79. <!--render facet: 440:0-->
  80. <!--render facet: 441:0-->
  81. </label>
  82. <select class=" select" size="1" aria-describedby="" id="9:114;a" data-aura-rendered-by="14:114;a" data-interactive-lib-uid="4">
  83. <!--render facet: 15:114;a-->
  84. <option label="" value="undefined"></option>
  85. <option label="" value="undefined"></option>
  86. </select>
Add Comment
Please, Sign In to add comment