Scenario
Users select from a dropdown list attribute when adding or editing metadata for an asset. Depending on what they select, the next attribute should be mandatory or not.
Example
Users can select 'Yes' or 'No' from a dropdown attribute called 'Usage Restrictions Apply'. If they select 'Yes', the next attribute (a text area called 'Restriction Notes') must be filled in. If they select 'No' from the dropdown they do not have to enter anything.
Solution
The solution is to make both the attributes mandatory, and then to use JavaScript in the dropdown attribute's 'OnChange' field to put a value 'N/A' into the text area if 'No' is selected by the user.
- Click 'Edit' next to the dropdown attribute in Admin > Attributes.
- Enter JavaScript into the 'onchange' field. Below is some example JavaScript that fits the above example. Note that the text area attribute in this example has an id of 706 (so has the id 'field706'), and the dropdown attribute value ID for 'Yes' is 20 and for 'No' is 21. You will need to substitute in your IDs accordingly.
Your attribute ID is included in the URL of the Attribute edit page - go to Admin > Attributes > Edit and you should see the URL in the following format:
example.assetbank-server.com/assetbank-example/action/viewEditAttribute?attributeId=706
The same applies to 'Yes' and 'No' values - you can locate these in the URL of Admin > Attribute > Edit list values > Edit.
if (this.value=='21' && document.getElementById('field706').value=='')
{
document.getElementById('field706').value='N/A';
}
else if (this.value=='20' && document.getElementById('field706').value=='N/A')
{
document.getElementById('field706').value='';
}
$('#field706').change();
Comments
0 comments
Please sign in to leave a comment.