+ Start a Discussion
Kumar GKumar G 

Attachment should be mandatory for below application types

Requirement is like : Attachment should be mandatory for below application types
i) Suport-User Creation
ii) Support-User Termination
iii) Support-User Update Permission

I have added the java script controller code in code sample , i am new to lightning. Some one implemented this component before , now i have to implement above requirement in this component .Please help me on this
JavaScript Controller :
({
	doSubmit : function(cmp, evt, hlpr) {
		var fileInput = cmp.find("fileId").get("v.files");
		var file = fileInput[0];
        
		var objFileReader = new FileReader();
        //alert(file);
        //console.log(file);
		objFileReader.onload = $A.getCallback(function() {
			var fileContents = objFileReader.result;
            var base64 = 'base64,';
           var dataStart = fileContents.indexOf(base64) + base64.length;
           fileContents = fileContents.substring(dataStart);
             console.log(encodeURIComponent(fileContents));
			//  call apex function SaveRegistrationDetail to save data in reg form
			//  also we have to pass RegForm as a parameter
			var casedata = cmp.get("v.casedata");

     
            // you can specify the base url
             //var redUrl ="https://ntgr--fullcopy.lightning.force.com/one/one.app#/sObject/";
             //window.open(redUrl+firstId);
  
			// create a one-time use instance of the SaveRegistrationDetail action
			// in the server-side controller
			var action = cmp.get("c.Savesupportform");
			action.setParams({
				casedata  : casedata,
				fileName: file.name,
				base64Data: encodeURIComponent(fileContents),
				contentType: file.type
			});
			// Create a callback that is executed after
			// the server-side action returns
			action.setCallback(this, function(response) {
				var state = response.getState();
                //alert(state);
				 if (state === "SUCCESS") {
					// Alert the user with the value returned
					// from the server
					cmp.set("v.isDataSubmitted", 'True');
					var parentId = response.getReturnValue();
					cmp.set("v.RegistrationRecordId",parentId);
					//alert('Record created succesfully'+''+ parentId);
                 window.location.href = "/" + parentId;                           
				}
				else if (state === "ERROR") {
					var errors = response.getError();
					if (errors) {
						if (errors[0] && errors[0].message) {
							console.log("Error message: " +
									 errors[0].message);
						}
					} else {
						console.log("Unknown error");
					}
				}
			});
			// $A.enqueueAction adds the server-side action to the queue.
			var radio=cmp.get('c.handleChange');
			$A.enqueueAction(action,radio); 
		});
        objFileReader.readAsDataURL(file);
	},
   
    handleFilesChange: function(component, event, helper) {
        //alert('fileselected');
        var fileName = 'No File Selected..';
        if (event.getSource().get("v.files").length > 0) {
            fileName = event.getSource().get("v.files")[0]['name'];
        }
        component.set("v.fileName", fileName);
        //alert(fileName);
    },
   
    handleClick : function (component ,event,helper){
       
        var nxtbtnonRadio=component.get("v.options");
        var nxtbtonSelect=component.find("mySelect");
        
        var nxtSelect=nxtbtonSelect.get("v.value");
          
        if(nxtbtnonRadio != null && nxtSelect.trim() != null ){
            component.set("isDataSubmitted", true);
        }
      
    },
   
    handleChange: function (cmp, event) {
        var changeValue = event.getParam("value");
        console.log("On change : "+changeValue);
        cmp.set("v.radioSelect", changeValue);
        //alert(changeValue);      
                                //var actn=component.get("c.handleClick");
           //actn.$meth$();
               
    },
   
   toggle: function (component, event, helper) {
   
    var sel = component.find("mySelect");
    var nav = sel.get("v.value");
   
    if (nav.trim() == "Support-User Creation") {
    component.set("v.userCreation", true);
     
        }
        else{
            component.set("v.userCreation", false);
        }
        if(nav.trim() == "Support-User Termination"){
        component.set("v.UserTermination", true);
       }
        else{
            component.set("v.UserTermination", false);
        }
         if(nav.trim() == "Support-User Update Permissions"){
                component.set("v.updatePermission" , true);
            }
        else{
            component.set("v.updatePermission" , false);
        }
    },
   
    nextButtonClickHandler : function(component, event, helper){
    var sel = component.find("mySelect");
    var nav = sel.get("v.value");
        if(nav !== '--None--' && component.get("v.radioSelect") !== '') {
            component.set("v.Isforsecond", true); 
        }
    },
   
    doInit : function(component, event, helper) {
       /*
        //Send LC Host as parameter to VF page so VF page can send message to LC; make it all dynamic
        component.set('v.lcHost', window.location.hostname);
 
        var frameSrc = '/apex/UploadFilePage?id=' + component.get('v.RegistrationRecordId') + '&lcHost=' + component.get('v.lcHost');
        console.log('frameSrc:' , frameSrc);
        component.set('v.frameSrc', frameSrc);
 
        //Add message listener
        window.addEventListener("message", function(event) {
 
            console.log('event.data:', event.data);
 
            // Handle the message
            if(event.data.state == 'LOADED'){
                //Set vfHost which will be used later to send message
                component.set('v.vfHost', event.data.vfHost);
                //alert('file loaded');
            }
 
            if(event.data.state == 'uploadFileSelected'){
                component.find('uploadFileButton').set('v.disabled', false);
                //alert('upload file selected');
               
            }
 
            if(event.data.state == 'fileUploadprocessed'){
                var uiMessage = component.find('uiMessage');
                //Disable Upload button until file is selected again
                component.find('uploadFileButton').set('v.disabled', true);
                //alert('file upload is true');
 
          $A.createComponents([
                        ["markup://ui:message",{
                            "body" : event.data.message,
                            "severity" : event.data.messageType,
                        }]
                    ],
                    function(components, status, errorMessage){
                       //alert('create component');
                        if (status === "SUCCESS") {
                            var message = components[0];
                            // set the body of the ui:message to be the ui:outputText
                            component.find('uiMessage').set("v.body", message);
                        }
                        else if (status === "INCOMPLETE") {
                            console.log("No response from server or client is offline.")
                            // Show offline error
                        }
                        else if (status === "ERROR") {
                            console.log("Error: " + errorMessage);
                            // Show error message
                        }
                    }
                );
            }
        }, false);
		*/
    },
    sendMessageone: function(component, event, helper) {
        //Clear UI message before trying for file upload again
        component.find('uiMessage').set("v.body",[]);
 
        //Prepare message in the format required in VF page
        var message = {
            "uploadFile" : true
        } ;
        //Send message to VF
        var sndmsg=component.set("v.sendmsg", true);
      
        helper.sendMessage(component, message);
    },
    setIframeCaseId : function(component, event, helper) {
        component.set("v.formSubmitStatus", "");
        var message = {
            "recordId" : event.target.value
        };
        helper.sendMessage(component, helper, message);
    },
    handleFormSubmit: function(component, event, helper) {
        //alert('file is uploading');
        console.log('file is uploading');
       var message = {
            "uploadFile" : true
        };
        helper.sendMessage(component, helper, message);
    }
})

.Thanks in advance..
Pradeep SinghPradeep Singh
Hi,
If you have used lightning:input tag in component then you can use required attribute to make it mandatory.
refer https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_input.htm

If this solves your problem, mark it as solved.