Forcing a minimum of 1 entry in a many-to-any double select

I am trying to work out how to ensure that a user submits at least one item in a many-to-many double select. There isn’t an Ajax call with these, so I’m looking to use the onValidate event - but am not sure what I can actually validate against?

There doesn’t seem any simple way to make it ‘mandatory’

Any ideas or suggestions?

I did work out I can do a sc_lookup() on the underlying N:N mapping table during the onAfterUpdate event, which then calls sc_error_message() and this displays the message and forces a ROLLBACK. This does feel a clumsy way round it though…

$q= "SELECT COUNT(*)
FROM staff_skills_map
WHERE staff_id = {staff_id}";

sc_lookup(rs, $q);

if (isset({rs[0][0]}))     // Row found
{
    if ({rs[0][0]} == 0)
	{
			sc_error_message('Skills: No skills allocated. <br/> 
                 Staff must have at least one skill.');
	}
}
		else     // No row found
{
	sc_error_message('Skill lookup table error');
}

Any other ideas?

Why not check the field length on the onValidate event to make sure there is something in the double select field? This avoids making the update and needing to query and roll back.

if (strlen({my_double_select_field}) == 0)
{
     // there is nothing in the double select
     sc_error_message('Skills: No skills allocated. <br />
     Staff must have at least one skill.');
}
1 Like

Great - thanks - works perfectly!