I'd like to avoid duplicate values being saved in the subform rows.
How can I use the nuSubformObject for this? I figure that the entry "columns" in the object could be checked for duplicates - but how do I do that in Javascript?
In nuBuilder Pro it was solved with this code (Javascript of main form):
Code: Select all
function nuBeforeSave()
{
// change this two parameters according to your needs
if ( !isDuplicateEntry('your_subform_name', 'your_field_name') ) {
return true;
}
}
/*
* Check duplicate field in a subform
*
* @param string pSubformName The name of the subform
* @param string fieldName The field name
*
* @return boolean True if a duplicate value is found
*/
function isDuplicateEntry(pSubformName, fieldName)
{
// Creates an array of the prefixes used for each row of the subform
var rowID = nuSubformRowArray(pSubformName, true);
// check if there is a duplicate value in subform field
tempArr = Array();
for (var i = 0 ; i < rowID.length; i++) {
// get the value of the field
fieldValue = $("#"+rowID[i]+fieldName).val();
if (tempArr.indexOf(fieldValue) >= 0) {
alert('Duplicate entry!');
return true;
} else {
tempArr.push($("#"+rowID[i]+fieldName).val());
}
}
return false;
}
Also, my subform object is a lookup, and I figured out how to filter the lookup for values that already exist in the database, hereby avoiding that a duplicate value can be chosen. But this, of course, does not work while adding/editing the subform values before they are saved.
Sql in Browse of the lookup form:
Code: Select all
SELECT DISTINCT bop_pos
FROM boxposition
Left join boxpos_mm on bop_id = bom_bop_id_FK
WHERE bop_pos NOT IN
(
SELECT DISTINCT bop_pos
FROM boxposition
Left join boxpos_mm on bop_id = bom_bop_id_FK
WHERE bom_ab_id_FK = "#dispID#"
)
GROUP BY bop_pos