When data is received from the backend in JSON format, it looks like this:
{
"data":{
"xyz":[
{
"number":"1",
"short_text":"Sign Contract",
"long_text":"Enter names after contract signing",
"is_photo":false
},
{
"number":"2",
"short_text":"Inform HR",
"long_text":"HR has its own workflows",
"is_photo":true
}
]
}
}
In the HTML code, a form is populated using ng-repeat:
<tr data-ng-repeat="choice in choices track by $index">
<td>{{choice.number}}</td>
<td><p>{{choice.short_text}}</p></td>
<td><input type="textbox" size="50" class="des-textinput" ng-model="choice.desc" required></td>
<td><input type="checkbox" ng-model="choice.include"></td>
<td><input type="file" id="abc{{$index}}" class="photo-upload"
file-model="pic{{$index}}" accept="image/*">
</td>
</tr>
The goal is to make the input type file required if is_photo
is true
in the received JSON. If is_photo
is false
, then it will not be required.
Based on the given JSON, the first input file will not be required because the value of is_photo
for the first row is false
, while the second one will be required as the value is true
.
To achieve this, additional conditional checks need to be implemented in the AngularJS code.