Here's how to have a conditionally required field. In this case we want a date field called date_golive_c to be required if a checkbox called transitioned_c is checked. If it gets unchecked we want it to not be required. This requires altering the editviewdefs.php in custom/modules/YOURMODULE/metadata. Good luck!
PHP Code:array (
'name' => 'transitioned_c',
/** [IC] eggsurplus: 2008/12/16 - make date_golive_c required if user checks the checkbox */
'customCode' => '
{literal}
<script language="javascript">
function requireGolive(transChecked) {
//need to iterate to find the correct index
for(var i = 0; i < validate["EditView"].length; i++){
if(validate["EditView"][i][nameIndex] == "date_golive_c") {
if(transChecked == true) {
validate["EditView"][i][requiredIndex] = true;
alert("Please fill in the Go-Live Date.");
} else { //do not require
validate["EditView"][i][requiredIndex] = false;
}
break;
}
}
}
</script>
{/literal}
{if $fields.transitioned_c.value == "1"}{assign var="TRANSITIONED_C_CHECKED" value="checked"}{else}{assign var="TRANSITIONED_C_CHECKED" value=""}{/if}<input name="transitioned_c" type="hidden" value="0"><input name="transitioned_c" onclick=\'requireGolive(this.checked);\' type="checkbox" class="checkbox" value="1" {$TRANSITIONED_C_CHECKED}>',
'label' => 'LBL_TRANSITIONED',
),


LinkBack URL
About LinkBacks





Reply With Quote
. Please also post it on the Wiki so it doesn't get lost!

Bookmarks