Field won't be saved (preGet)
Field won't be saved (preGet)
Hello,
i would like to have only those entries displayed from a "dropdown", for which you have the corresponding authorization.
this works so far, only that the field "XRM_Timeslips.fa_billingstatus_id" is not saved when sending the form.
->on('preGet', function ($editor, $id) {
$m_user = new User_Model;
$userid = $_SESSION['login']['userid'];
if ($m_user->hasPermission("updateEverything", "xrmTimeslips", $userid) == true) {
$editor
->fields(
Field::inst('XRM_Timeslips.fa_billingstatus_id')
->options(Options::inst()
->table('FA_BillingStatus')
->value('id')
->label('Name')
->where(function ($q) {
$q->where(function ($r) {
$r->where('FA_BillingStatus.id', 4);
$r->or_where('FA_BillingStatus.id', 5);
$r->or_where('FA_BillingStatus.id', 8);
});
})
)
);
} else {
$editor
->fields(
Field::inst('XRM_Timeslips.fa_billingstatus_id')
->options(Options::inst()
->table('FA_BillingStatus')
->value('id')
->label('Name')
->where(function ($q) {
$q->where(function ($r) {
$r->where('FA_BillingStatus.id', 5);
});
})
)
->validator('Validate::dbValues')
->validator('Validate::notEmpty')
);
}
})
$(function() {
var editor;
editor = new $.fn.dataTable.Editor({
ajax: "ajax/xrm/timeslips/processData.php",
table: "#table_[@ID UID]",
template: '#form_[@ID UID]',
fields: [{
label: "ID:",
name: 'XRM_Timeslips.id',
type: 'readonly'
}, {
label: "FA-Status:",
name: "XRM_Timeslips.fa_billingstatus_id",
opts: {
multiple: false,
placeholder: 'auswählen'
},
"type": "select2",
} ]
});
This discussion has been closed.
Replies
If you add
->debug(true)
just before the->process(...)
method in the PHP, could you show me the JSON return from the server when you do an edit please?Thanks,
Allan
Thanks for that! Do you define the
fa_billingstatus_id
field in the Editor PHP anywhere other than in thepreGet
event handler? That would define it only when fetching data from the database which is reflected in the SQL statements above where its only used in the SELECT.Allan
if i define it also in:
then this throws the following error:
Duplicate field detected - a field with the name
XRM_Timeslips.fa_billingstatus_id
already exists.do you have an idea?
Apologies - I missed your previous reply. If you change the
select2
to be justselect
for the field type, does it then edit correctly? If so, then when it isselect2
have a look at the data submitted from the browser in the "headers" section of the XHR of the network inspector.Allan