Skip to content

Instantly share code, notes, and snippets.

@grantholle
Last active October 11, 2021 13:40
Show Gist options
  • Save grantholle/d1ff87f881376f4cf87f8d66e1fbb4a4 to your computer and use it in GitHub Desktop.
Save grantholle/d1ff87f881376f4cf87f8d66e1fbb4a4 to your computer and use it in GitHub Desktop.
Missy jQuery help
<script>
// Keep everything scoped to this function
// Run on startup
$j(function() {
// Storing as a variable
const $fpCompl = $j('#fpcompl')
// Add any other 'editable' values you want to this array
const editable = [
'No(AR)',
'Yes(DE)'
]
function fpCompComment () {
const value = $fpCompl.val()
// Check compliance value
if (editable.includes(value)) {
// make required and editable
// since we're returning here, the `else` isn't necessary
return $j('#fp_cmt')
.prop('readonly', false)
.prop('required', true)
.removeClass('disabled')
.addClass('required');
}
// not editable not required
$j('#fp_cmt')
.val('')
.prop('readonly', true)
.prop('required', false)
.removeClass('required');
};
// Initial load.
fpCompComment();
// Now set up listener for any changes in compliance
$fpCompl.on('change', fpCompComment);
});
</script>
@gitmissy
Copy link

Awesome - thank you so much - it is working now!
image

@grantholle
Copy link
Author

@gitmissy awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment