Checking if rendered lightning:input components are populatedHow to add tooltips to lightning:input components?How to keep spinner moving till components are getting rendered in <aura:iteration>Lightning:input label attribute not rendered when type=“checkbox-button”Are dynamically created components bound the same as child components?Lightning:input elements updateFree Text fields in Communities with <lightning:input> in Lightning ComponentsHow to collect errors from many Lightning:Input componentslightning:input field hiddenlightning:input methods - which are available?How to access aura:id of a tag present in child component in a parent component controller

Can anyone tell me why this program fails?

Bash replace string at multiple places in a file from command line

What options are left, if Britain cannot decide?

Why do Australian milk farmers need to protest supermarkets' milk price?

Provisioning profile doesn't include the application-identifier and keychain-access-groups entitlements

How could a female member of a species produce eggs unto death?

PTIJ: Who should pay for Uber rides: the child or the parent?

How to make healing in an exploration game interesting

Simulating rnorm() using runif()

Word for a person who has no opinion about whether god exists

How do anti-virus programs start at Windows boot?

What has been your most complicated TikZ drawing?

An Accountant Seeks the Help of a Mathematician

Does this AnyDice function accurately calculate the number of ogres you make unconcious with three 4th-level castings of Sleep?

About parabolic Kazhdan Lusztig polynomials

Meaning of "SEVERA INDEOVI VAS" from 3rd Century slab

How could a scammer know the apps on my phone / iTunes account?

Plot a function of two variables equal 0

Happy pi day, everyone!

Why do passenger jet manufacturers design their planes with stall prevention systems?

How to generate globally unique ids for different tables of the same database?

Informing my boss about remarks from a nasty colleague

Cultural lunch issues

Checking if rendered lightning:input components are populated



Checking if rendered lightning:input components are populated


How to add tooltips to lightning:input components?How to keep spinner moving till components are getting rendered in <aura:iteration>Lightning:input label attribute not rendered when type=“checkbox-button”Are dynamically created components bound the same as child components?Lightning:input elements updateFree Text fields in Communities with <lightning:input> in Lightning ComponentsHow to collect errors from many Lightning:Input componentslightning:input field hiddenlightning:input methods - which are available?How to access aura:id of a tag present in child component in a parent component controller













2















I am building a Lightning Component form with sections. I want to display a big check mark icon on the section if all the rendered lightning:input fields are filled out.



I have successfully tested this approach:



Markup:



<lightning:input aura:id="fieldId" type="number" name="input1" required="true" label="Enter a number" />
<lightning:input aura:id="fieldId" type="number" name="input2" required="true" label="Enter another number" />
<lightning:button variant="brand" label="Check" value="check" onclick="!c.testMe"/>


Controller:



testMe : function(component) 

var allComplete = component.find('fieldId').reduce(function (validSoFar, inputCmp)
return validSoFar && !inputCmp.get('v.validity').valueMissing;
, true);
if (allComplete)
console.log('All fields complete!');
else
console.log('Some fields are missing values.');




The problem arises when I start making the form dynamic using aura:if to conditionally hide lightning:input fields.



If I change my markup to this, the function fails and nothing shows up in the console:



<lightning:input aura:id="fieldId" type="number" name="input1" required="true" label="Enter a number" />
<aura:if isTrue="! false ">
<lightning:input aura:id="fieldId" type="number" name="input2" required="true" label="Enter another number" />
</aura:if>
<lightning:button variant="brand" label="Check" value="check" onclick="!c.testMe"/>



Based on the helpful answer from itzmukeshy7, here is my revised, working controller function:



testMe : function(component) 

var rows = component.find('fieldId');
var elements = [].concat(rows ,









share|improve this question




























    2















    I am building a Lightning Component form with sections. I want to display a big check mark icon on the section if all the rendered lightning:input fields are filled out.



    I have successfully tested this approach:



    Markup:



    <lightning:input aura:id="fieldId" type="number" name="input1" required="true" label="Enter a number" />
    <lightning:input aura:id="fieldId" type="number" name="input2" required="true" label="Enter another number" />
    <lightning:button variant="brand" label="Check" value="check" onclick="!c.testMe"/>


    Controller:



    testMe : function(component) 

    var allComplete = component.find('fieldId').reduce(function (validSoFar, inputCmp)
    return validSoFar && !inputCmp.get('v.validity').valueMissing;
    , true);
    if (allComplete)
    console.log('All fields complete!');
    else
    console.log('Some fields are missing values.');




    The problem arises when I start making the form dynamic using aura:if to conditionally hide lightning:input fields.



    If I change my markup to this, the function fails and nothing shows up in the console:



    <lightning:input aura:id="fieldId" type="number" name="input1" required="true" label="Enter a number" />
    <aura:if isTrue="! false ">
    <lightning:input aura:id="fieldId" type="number" name="input2" required="true" label="Enter another number" />
    </aura:if>
    <lightning:button variant="brand" label="Check" value="check" onclick="!c.testMe"/>



    Based on the helpful answer from itzmukeshy7, here is my revised, working controller function:



    testMe : function(component) 

    var rows = component.find('fieldId');
    var elements = [].concat(rows ,









    share|improve this question


























      2












      2








      2








      I am building a Lightning Component form with sections. I want to display a big check mark icon on the section if all the rendered lightning:input fields are filled out.



      I have successfully tested this approach:



      Markup:



      <lightning:input aura:id="fieldId" type="number" name="input1" required="true" label="Enter a number" />
      <lightning:input aura:id="fieldId" type="number" name="input2" required="true" label="Enter another number" />
      <lightning:button variant="brand" label="Check" value="check" onclick="!c.testMe"/>


      Controller:



      testMe : function(component) 

      var allComplete = component.find('fieldId').reduce(function (validSoFar, inputCmp)
      return validSoFar && !inputCmp.get('v.validity').valueMissing;
      , true);
      if (allComplete)
      console.log('All fields complete!');
      else
      console.log('Some fields are missing values.');




      The problem arises when I start making the form dynamic using aura:if to conditionally hide lightning:input fields.



      If I change my markup to this, the function fails and nothing shows up in the console:



      <lightning:input aura:id="fieldId" type="number" name="input1" required="true" label="Enter a number" />
      <aura:if isTrue="! false ">
      <lightning:input aura:id="fieldId" type="number" name="input2" required="true" label="Enter another number" />
      </aura:if>
      <lightning:button variant="brand" label="Check" value="check" onclick="!c.testMe"/>



      Based on the helpful answer from itzmukeshy7, here is my revised, working controller function:



      testMe : function(component) 

      var rows = component.find('fieldId');
      var elements = [].concat(rows ,









      share|improve this question
















      I am building a Lightning Component form with sections. I want to display a big check mark icon on the section if all the rendered lightning:input fields are filled out.



      I have successfully tested this approach:



      Markup:



      <lightning:input aura:id="fieldId" type="number" name="input1" required="true" label="Enter a number" />
      <lightning:input aura:id="fieldId" type="number" name="input2" required="true" label="Enter another number" />
      <lightning:button variant="brand" label="Check" value="check" onclick="!c.testMe"/>


      Controller:



      testMe : function(component) 

      var allComplete = component.find('fieldId').reduce(function (validSoFar, inputCmp)
      return validSoFar && !inputCmp.get('v.validity').valueMissing;
      , true);
      if (allComplete)
      console.log('All fields complete!');
      else
      console.log('Some fields are missing values.');




      The problem arises when I start making the form dynamic using aura:if to conditionally hide lightning:input fields.



      If I change my markup to this, the function fails and nothing shows up in the console:



      <lightning:input aura:id="fieldId" type="number" name="input1" required="true" label="Enter a number" />
      <aura:if isTrue="! false ">
      <lightning:input aura:id="fieldId" type="number" name="input2" required="true" label="Enter another number" />
      </aura:if>
      <lightning:button variant="brand" label="Check" value="check" onclick="!c.testMe"/>



      Based on the helpful answer from itzmukeshy7, here is my revised, working controller function:



      testMe : function(component) 

      var rows = component.find('fieldId');
      var elements = [].concat(rows ,






      lightning-aura-components lightning






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 5 hours ago







      Matthew Souther

















      asked 6 hours ago









      Matthew SoutherMatthew Souther

      935




      935




















          2 Answers
          2






          active

          oldest

          votes


















          3














          This is all fine, there is a trick which is very much hidden in the documentation:



          Here is what the documentation says:
          find documentation



          So we can handle this with concat method of array:



          var rows = c.find('rowSelector');
          var elements = [].concat(rows || []);
          /* Now here the elements will always be an array, and won't break your code anymore. */





          share|improve this answer

























          • +1 Love this solution, even shorter than what I was using previously.

            – sfdcfox
            5 hours ago











          • Many thanks! Here is my updated controller function, which works. testMe : function(component) var rows = component.find('fieldId'); var elements = [].concat(rows ,

            – Matthew Souther
            5 hours ago












          • Great, if it worked for you.

            – itzmukeshy7
            5 hours ago


















          1














          When running your example, I'm getting an error saying reduce is not a valid function. You can enable debug mode for lightning components to get these errors.enter image description here



          The reason for this is your component.find(...) method.
          Component.find has two return types. Either an Object or Object[].



          In the first example you have multiple instances of a component with id "fieldId". Thus the return type will be a list of aura components.



          In the second example there is only one aura component as the other one is conditionally rendered. Hence only one component with id "fieldId" is found. Component.find will return a single object and not a array of objects.



          You can resolve the issue by first checking if the result of component.find is an array. If not then add it to an array and apply the same reduce method for simplicity sake.






          share|improve this answer


















          • 2





            Actually, component.find(...) returns three types of value, not two: 1. An array, if we have more than one element with the provided id. 2. An element, if we have a unique element with the provided id. 3. undefined, if we don't have any element with the provided id.

            – itzmukeshy7
            5 hours ago











          • Thanks for the pointer to use debug mode for Lightning Components -- I will look into that.

            – Matthew Souther
            5 hours ago










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "459"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f253856%2fchecking-if-rendered-lightninginput-components-are-populated%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          This is all fine, there is a trick which is very much hidden in the documentation:



          Here is what the documentation says:
          find documentation



          So we can handle this with concat method of array:



          var rows = c.find('rowSelector');
          var elements = [].concat(rows || []);
          /* Now here the elements will always be an array, and won't break your code anymore. */





          share|improve this answer

























          • +1 Love this solution, even shorter than what I was using previously.

            – sfdcfox
            5 hours ago











          • Many thanks! Here is my updated controller function, which works. testMe : function(component) var rows = component.find('fieldId'); var elements = [].concat(rows ,

            – Matthew Souther
            5 hours ago












          • Great, if it worked for you.

            – itzmukeshy7
            5 hours ago















          3














          This is all fine, there is a trick which is very much hidden in the documentation:



          Here is what the documentation says:
          find documentation



          So we can handle this with concat method of array:



          var rows = c.find('rowSelector');
          var elements = [].concat(rows || []);
          /* Now here the elements will always be an array, and won't break your code anymore. */





          share|improve this answer

























          • +1 Love this solution, even shorter than what I was using previously.

            – sfdcfox
            5 hours ago











          • Many thanks! Here is my updated controller function, which works. testMe : function(component) var rows = component.find('fieldId'); var elements = [].concat(rows ,

            – Matthew Souther
            5 hours ago












          • Great, if it worked for you.

            – itzmukeshy7
            5 hours ago













          3












          3








          3







          This is all fine, there is a trick which is very much hidden in the documentation:



          Here is what the documentation says:
          find documentation



          So we can handle this with concat method of array:



          var rows = c.find('rowSelector');
          var elements = [].concat(rows || []);
          /* Now here the elements will always be an array, and won't break your code anymore. */





          share|improve this answer















          This is all fine, there is a trick which is very much hidden in the documentation:



          Here is what the documentation says:
          find documentation



          So we can handle this with concat method of array:



          var rows = c.find('rowSelector');
          var elements = [].concat(rows || []);
          /* Now here the elements will always be an array, and won't break your code anymore. */






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 1 hour ago









          Mark Pond

          18.5k13288




          18.5k13288










          answered 6 hours ago









          itzmukeshy7itzmukeshy7

          2,349922




          2,349922












          • +1 Love this solution, even shorter than what I was using previously.

            – sfdcfox
            5 hours ago











          • Many thanks! Here is my updated controller function, which works. testMe : function(component) var rows = component.find('fieldId'); var elements = [].concat(rows ,

            – Matthew Souther
            5 hours ago












          • Great, if it worked for you.

            – itzmukeshy7
            5 hours ago

















          • +1 Love this solution, even shorter than what I was using previously.

            – sfdcfox
            5 hours ago











          • Many thanks! Here is my updated controller function, which works. testMe : function(component) var rows = component.find('fieldId'); var elements = [].concat(rows ,

            – Matthew Souther
            5 hours ago












          • Great, if it worked for you.

            – itzmukeshy7
            5 hours ago
















          +1 Love this solution, even shorter than what I was using previously.

          – sfdcfox
          5 hours ago





          +1 Love this solution, even shorter than what I was using previously.

          – sfdcfox
          5 hours ago













          Many thanks! Here is my updated controller function, which works. testMe : function(component) var rows = component.find('fieldId'); var elements = [].concat(rows ,

          – Matthew Souther
          5 hours ago






          Many thanks! Here is my updated controller function, which works. testMe : function(component) var rows = component.find('fieldId'); var elements = [].concat(rows ,

          – Matthew Souther
          5 hours ago














          Great, if it worked for you.

          – itzmukeshy7
          5 hours ago





          Great, if it worked for you.

          – itzmukeshy7
          5 hours ago













          1














          When running your example, I'm getting an error saying reduce is not a valid function. You can enable debug mode for lightning components to get these errors.enter image description here



          The reason for this is your component.find(...) method.
          Component.find has two return types. Either an Object or Object[].



          In the first example you have multiple instances of a component with id "fieldId". Thus the return type will be a list of aura components.



          In the second example there is only one aura component as the other one is conditionally rendered. Hence only one component with id "fieldId" is found. Component.find will return a single object and not a array of objects.



          You can resolve the issue by first checking if the result of component.find is an array. If not then add it to an array and apply the same reduce method for simplicity sake.






          share|improve this answer


















          • 2





            Actually, component.find(...) returns three types of value, not two: 1. An array, if we have more than one element with the provided id. 2. An element, if we have a unique element with the provided id. 3. undefined, if we don't have any element with the provided id.

            – itzmukeshy7
            5 hours ago











          • Thanks for the pointer to use debug mode for Lightning Components -- I will look into that.

            – Matthew Souther
            5 hours ago















          1














          When running your example, I'm getting an error saying reduce is not a valid function. You can enable debug mode for lightning components to get these errors.enter image description here



          The reason for this is your component.find(...) method.
          Component.find has two return types. Either an Object or Object[].



          In the first example you have multiple instances of a component with id "fieldId". Thus the return type will be a list of aura components.



          In the second example there is only one aura component as the other one is conditionally rendered. Hence only one component with id "fieldId" is found. Component.find will return a single object and not a array of objects.



          You can resolve the issue by first checking if the result of component.find is an array. If not then add it to an array and apply the same reduce method for simplicity sake.






          share|improve this answer


















          • 2





            Actually, component.find(...) returns three types of value, not two: 1. An array, if we have more than one element with the provided id. 2. An element, if we have a unique element with the provided id. 3. undefined, if we don't have any element with the provided id.

            – itzmukeshy7
            5 hours ago











          • Thanks for the pointer to use debug mode for Lightning Components -- I will look into that.

            – Matthew Souther
            5 hours ago













          1












          1








          1







          When running your example, I'm getting an error saying reduce is not a valid function. You can enable debug mode for lightning components to get these errors.enter image description here



          The reason for this is your component.find(...) method.
          Component.find has two return types. Either an Object or Object[].



          In the first example you have multiple instances of a component with id "fieldId". Thus the return type will be a list of aura components.



          In the second example there is only one aura component as the other one is conditionally rendered. Hence only one component with id "fieldId" is found. Component.find will return a single object and not a array of objects.



          You can resolve the issue by first checking if the result of component.find is an array. If not then add it to an array and apply the same reduce method for simplicity sake.






          share|improve this answer













          When running your example, I'm getting an error saying reduce is not a valid function. You can enable debug mode for lightning components to get these errors.enter image description here



          The reason for this is your component.find(...) method.
          Component.find has two return types. Either an Object or Object[].



          In the first example you have multiple instances of a component with id "fieldId". Thus the return type will be a list of aura components.



          In the second example there is only one aura component as the other one is conditionally rendered. Hence only one component with id "fieldId" is found. Component.find will return a single object and not a array of objects.



          You can resolve the issue by first checking if the result of component.find is an array. If not then add it to an array and apply the same reduce method for simplicity sake.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 6 hours ago









          Lieven JuwetLieven Juwet

          762413




          762413







          • 2





            Actually, component.find(...) returns three types of value, not two: 1. An array, if we have more than one element with the provided id. 2. An element, if we have a unique element with the provided id. 3. undefined, if we don't have any element with the provided id.

            – itzmukeshy7
            5 hours ago











          • Thanks for the pointer to use debug mode for Lightning Components -- I will look into that.

            – Matthew Souther
            5 hours ago












          • 2





            Actually, component.find(...) returns three types of value, not two: 1. An array, if we have more than one element with the provided id. 2. An element, if we have a unique element with the provided id. 3. undefined, if we don't have any element with the provided id.

            – itzmukeshy7
            5 hours ago











          • Thanks for the pointer to use debug mode for Lightning Components -- I will look into that.

            – Matthew Souther
            5 hours ago







          2




          2





          Actually, component.find(...) returns three types of value, not two: 1. An array, if we have more than one element with the provided id. 2. An element, if we have a unique element with the provided id. 3. undefined, if we don't have any element with the provided id.

          – itzmukeshy7
          5 hours ago





          Actually, component.find(...) returns three types of value, not two: 1. An array, if we have more than one element with the provided id. 2. An element, if we have a unique element with the provided id. 3. undefined, if we don't have any element with the provided id.

          – itzmukeshy7
          5 hours ago













          Thanks for the pointer to use debug mode for Lightning Components -- I will look into that.

          – Matthew Souther
          5 hours ago





          Thanks for the pointer to use debug mode for Lightning Components -- I will look into that.

          – Matthew Souther
          5 hours ago

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Salesforce Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f253856%2fchecking-if-rendered-lightninginput-components-are-populated%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Masuk log Menu navigasi

          16 Maret Daftar isi Peristiwa | Kelahiran | Meninggal | Hari raya dan peringatan | Menu navigasis

          ジョン・ファウルズ