0

I have file input and radio:

<lightning:input aura:id="file-input"
                             label="Attachment"
                             type="file"
                             accept=".pdf"
                             files="{!v.filesToBeUploaded}"
                             onchange="{!c.onFileUploaded}"
                             multiple="true"
                             required="{!v.opt== 'value1'}"
            />
<lightning:radioGroup name="radio1"
                                  label="label1"
                                  options="{!v.opts}"
                                  value="{!v.opt}"
                                  type="radio"
                                  required="true"
            />

And button that clears files:

<lightning:buttonIcon iconName="utility:clear" onclick="{!c.clearFiles}" alternativeText="clear" />

clearFiles:function(component,event,helper) {
        component.find("file-input").set("v.files", []); // experimental
        component.set("v.filesToBeUploaded", []);
    },

Here is scenario: When option 1 is selected, fileinput is required. I select files, after selection file names are displayed in list. When I press clear, list becomes empty. Both files attribute on component level and files attribute on input are empty.

But when I change radio value again, previously selected files are selected again. Why this happens?

I also tried this but no result.

onRadioChange:function(component,event,helper) {
    if (component.get("v.opt") == 'value1') {
        component.find("file-input").set("v.required", true);
    } else {
        component.find("file-input").set("v.required", false);
    }
},
  • Are you able to post your code in entirety so we can easily replicate the issue on our end and figure this out? Otherwise we will be spending more time setting it up on our end to match your use case than solving the actual issue. – Lightning Evangelist Aug 8 '18 at 11:51
  • @Kal nevermind I will make one-way binding – Vladyslav K Aug 14 '18 at 12:27
  • @vladdihoney are you able to resolve this? If yes can you post the answer – cartman Jul 29 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.