Title should really be 'How to set a custom field as required'.
I have two custom input fields on an Edit Page, whether they are visible depends on the value of the accom_type field (a radio button), if they are visible then they need to be required fields and they are initially populated with the current values extracted from a database field by the before-display event. There is code in the before-record-updated event to copy the data from the two custom fields back to the database field.
The HTML from the visual editor in HTML mode, which has been added manually.
<TR class="{$fielddispclass_st reet1}" id="cstrow1">
<TD class="rnr-label" stylewidth: 110px;" rowspan="1" colspan="1">
Flat No.
</TD>
<TD class="rnr-control style3" style="width: 91px;" rowspan="1" colspan="1">
<INPUT id="cstflat" style="width: 66px; height: 16px;" type="text" size="3">
</TD>
<TD class="rnr-control style3 runner-cc" style="width: 133px;" rowspan="1" colspan="1">
<P align="right">
Building Name
</P>
</TD>
<TD class="rnr-control style3 runner-cc" style="width: 242px;" rowspan="1" colspan="1">
<INPUT id="cstbldg" style="width: 221px; height: 16px;" type="text" size="23">
</TD>
</TR>
Annotated code
// accom_type field from edit page
var ctrl_accom = Runner.getControl(pageid, 'accom_type');
//Proxy values set up by before display event code
var bldg = proxy.pxy_bldg;
var flat = proxy.pxy_flat;
$(document).ready(function(){
// cstflat is first custom field - here its is automatically blanked out when it gets focus - working OK.
$('#cstflat').focus(function(e) {
$('#cstflat').val('');
});
// switch on the values of the accom_type field which are Flat, House, NFA
switch(ctrl_accom.getValue()) {
// Flat is where I want to make the cstflat and cstbldg custom fields required
case 'Flat':
// this next statement doesn't work
$('#cstflat').attr('required', true);
// next set of statements all work correctly
$('#cstflat').val(flat);
$('#cstbldg').val(bldg);
$('#cstrow1').show(); // this is making the row with cstflat and cstbldg visible
pageObj.hideField('street1');
ctrl_str2.addValidation('IsRequired') ;
break;
I have also tried:
$('#cstflat').prop('required')
document.getElementById("cstflat").required = true;
which didn't work either.
Having trawled through the forum posts, and Googled extensively I'd be very grateful for any suggestions as I'm now stumped.
Thanks