You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We often get asked about creating unique record identifiers, using the PK as part of a pre-formatted string, and quite often some other element value, like "SKU-{rowid}-{parts___part_name}" etc.
Of course the chicken and egg is that this can't be done till after the form is first submitted, and some folk want it set "now".
In the past, I have written form plugins for clients, running onLoad, which for various reasons need to know a rowid for one app specific reason or other. The plugin just checks for a rowid, and if 0, manually poke a row in to the table, along with enough other values to satisfy Fabrik (like default values), then redirects to an edit link for the newly inserted rowid. So basically, hitting "Add" ends up being "Edit a new row", so the rowid is known the first time the user sees the page.
Seems like this might be something which would be generally useful, which could just be a simple "Pre-Create Row" form, and an optional "Record ID" element type, although probably need to call it something other than ID, to avoid confusion with PK / internal ID.
The Record ID element probably wouldn't do anything a field element with a default and an sprintf() statement couldn't do, or even a calc with "AJAX calc" enabled. But it'd probably be cleaner to just build a specific plugin for it, that is read only, param wise just has a simple "Template string" (with optional %s formatting) that groks placeholders, and does AJAX updates like the calc.
-- hugh
The text was updated successfully, but these errors were encountered:
I just had a thought which might make this generic chicken and rowid situation a little easier, for folk who need to do some processing involving the newling created PK of a new row, which is to add something like an onAfterStore plugin hook, right before we call the onBeforeCalculation hook the end of the form model processToDb().
If any of the onAfterStore hooks return true, that means they've updated $formModel->_formData, and would like use to re-write the main row. Don't worry about joined data, that would just be a nightmare. But basically do what we do for a one-to-one where the FK is on the main table, like:
... which would set the part_num to SKU-00364 (or whatever) on submission of a new form.
Or, to make it slightly easier,build a little generic element type to build a string, as per the "Record ID" stuff in my previous post, automagically does that when creating a new row.
New feature suggestion.
We often get asked about creating unique record identifiers, using the PK as part of a pre-formatted string, and quite often some other element value, like "SKU-{rowid}-{parts___part_name}" etc.
Of course the chicken and egg is that this can't be done till after the form is first submitted, and some folk want it set "now".
In the past, I have written form plugins for clients, running onLoad, which for various reasons need to know a rowid for one app specific reason or other. The plugin just checks for a rowid, and if 0, manually poke a row in to the table, along with enough other values to satisfy Fabrik (like default values), then redirects to an edit link for the newly inserted rowid. So basically, hitting "Add" ends up being "Edit a new row", so the rowid is known the first time the user sees the page.
Seems like this might be something which would be generally useful, which could just be a simple "Pre-Create Row" form, and an optional "Record ID" element type, although probably need to call it something other than ID, to avoid confusion with PK / internal ID.
The Record ID element probably wouldn't do anything a field element with a default and an sprintf() statement couldn't do, or even a calc with "AJAX calc" enabled. But it'd probably be cleaner to just build a specific plugin for it, that is read only, param wise just has a simple "Template string" (with optional %s formatting) that groks placeholders, and does AJAX updates like the calc.
-- hugh
The text was updated successfully, but these errors were encountered: