creating a mandatory field in ui page?

caffry
Kilo Guru

i have a field which should have mandatory symbol (*) and when i enter the values it should change from red to grey..

<label>Name : </label>

<input type="text" ng-model="name" id="demo"  />

can i use it for the above the code...without using jelly script

1 ACCEPTED SOLUTION

Here is the full code

HTML

<label for="input1" id="inputLabel" >Name</label>
  <input type="text" ng-model="name" onchange="checkMandatory()" id="demo"  />

 

Client script

document.getElementById('inputLabel').setAttribute("class", "required");

function checkMandatory(){
if(document.getElementById('demo')!="")
document.getElementById('inputLabel').setAttribute("class", "notrequired");

}

css

label.required::before {
  content: '*';
  margin-right: 4px;
  color: red;
}
label.notrequired::before {
  content: '*';
  margin-right: 4px;
  color: grey;
}

 

View solution in original post

26 REPLIES 26

The same error 

Error at line (12) Attribute name "required" associated with an element type "input" must be followed by the ' = ' character.

Hi 

Try adding 

<input type="text" id="demo" th:required="required"/>

can i know whats that th..

when i use the above code it shows me an error on th

Jaydeep Parmar
Kilo Guru

Hi Caffry,

Check OOTB UI page named $pwd_change

and use <span class="required-marker"></span> before any html tag

Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.

Jaydeep Parmar

find_real_file.png

 

i have mentioned what you have said in the below script still it didnt work

it showing the below error in my code

Error at line (115) Attribute name "required" associated with an element type "input" must be followed by the ' = ' character.

find_real_file.png