You need to sign in to do that
Don't have an account?
Atul Shendge 2
How to make a field mandatory using lightning component controller
Hi,
In my scenario, I have a field called question and it should be mandatory, If User missed to enter this field it should throw an error and I am trying this to acheive through Lightning component.
Below is the component code which is working fine:
<lightning:layout>
<lightning:layoutitem><p style="color:red;">*</p></lightning:layoutitem>
<lightning:layoutitem>
<tr><td>
<div style="font-size:14px;color:black;"><B>Question 1 </B> </div>
</td></tr>
<p>
<br/>
What is the invention? What problem does the invention solve? What are the features of the invention and how do they solve the problem? Describe your implementation(s) of the invention using examples. (Note: you can upload drawings and other documents in Step 5.)
</p>
<tr><td> <lightning:inputRichText aura:id="TxtAnswer1" onblur="{!c.assignAnswer1}" value="{!v.QuestAnswer1}"/></td></tr>
</lightning:layoutitem>
</lightning:layout>
<br/>
Here is the Controller and I think something needs to be added in this but I am not sure, Below is the Controller code:
{
assignAnswer1 : function(component, event, helper) {
var Answer1=component.find("TxtAnswer1").get("v.value");
component.set("v.QuestAnswer1", Answer1);
Any help would be really appreciated.
Regards,
Atul Shendge
In my scenario, I have a field called question and it should be mandatory, If User missed to enter this field it should throw an error and I am trying this to acheive through Lightning component.
Below is the component code which is working fine:
<lightning:layout>
<lightning:layoutitem><p style="color:red;">*</p></lightning:layoutitem>
<lightning:layoutitem>
<tr><td>
<div style="font-size:14px;color:black;"><B>Question 1 </B> </div>
</td></tr>
<p>
<br/>
What is the invention? What problem does the invention solve? What are the features of the invention and how do they solve the problem? Describe your implementation(s) of the invention using examples. (Note: you can upload drawings and other documents in Step 5.)
</p>
<tr><td> <lightning:inputRichText aura:id="TxtAnswer1" onblur="{!c.assignAnswer1}" value="{!v.QuestAnswer1}"/></td></tr>
</lightning:layoutitem>
</lightning:layout>
<br/>
Here is the Controller and I think something needs to be added in this but I am not sure, Below is the Controller code:
{
assignAnswer1 : function(component, event, helper) {
var Answer1=component.find("TxtAnswer1").get("v.value");
component.set("v.QuestAnswer1", Answer1);
Any help would be really appreciated.
Regards,
Atul Shendge
Update with below snippet.
Thanks,
Vinay Kumar
Thanks for the reply. But I am facing below error.
https://developer.salesforce.com/docs/component-library/bundle/lightning-input-rich-text/documentation
If it solves your issue please mark this as correct, it may help others.
Error says you cannot use required attribute in input text. You need to check for alternate ui: inputtext or implement custom JS functionality.
https://salesforce.stackexchange.com/questions/210911/make-a-lightning-uiinputtext-required
Thanks,
Vinay Kumar
in HTML
<aura:attribute name='txtAnswer1Valid' type='Boolean' default='false'/>
<lightning:inputRichText aura:id="TxtAnswer1" onblur="{!c.assignAnswer1}" value="{!v.QuestAnswer1}" valid="{!v.txtAnswer1Valid}" />
assignAnswer1 : function(component, event, helper) {
if (!component.get("v.TxtAnswer1"))
{
component.set("v.txtAnswer1Valid",false);
return;
}
else
{
component.set("v.txtAnswer1Valid",true);
}
var Answer1=component.find("TxtAnswer1").get("v.value");
component.set("v.QuestAnswer1", Answer1);