This topic is locked

Date/Time Field gets NULL when field is disabled

3/17/2024 3:52:52 PM
PHPRunner General questions
D
druck281 author

On one of my tables, I have two feilds that capture the username and date/time when a record is added. On the Add page, the fields are hidden and capture the current user and date/time and properly writes it to the database.

When I display the Edit page, I want the user to see the values but not be able to edit them. I use the following in the JS OnLoad event to disable the field.

var ctrlBy = Runner.getControl(pageid,'ReportedBy');
var ctrlDate=Runner.getControl(pageid,'ReportedDate');

ctrlBy.setDisabled();
ctrlDate.setDisabled();

When the user clicks save on the Edit page, that Date/Time field (and only that field) gets set to NULL. The username remains unchanged. There is no other code acting on this field. Any idea why this is happening?

D
druck281 author 3/17/2024

I found that I can use '.makeReadOnly' as a workaround for this. I will leave it open for any other thoughts but this is working so far.

C
cristi 3/18/2024

This is a case of RTFM: JavaScript API: Control object > setDisabled()

Remarks

Disabled controls are NOT submitted with the form and are not saved in the database. Disabled controls will be filled by the Autofill feature. You can apply default values to Disabled controls.

D
druck281 author 3/18/2024

Pretty ballsy...thanks cristi. I did read the manual and I saw that disabled controls are not submitted with the form. Forgive my ignorance for thinking it would not need to be submitted since it already existed in the database before the Edit page was loaded. If by 'not submitted with the form', values are actually removed from the DB, why does this only happen to one of the two disabled fields? The other disabled field on the same form has no issues and that value remains unchanged after the form is submitted.

C
cristi 3/19/2024

Maybe you are mistaken "read only" with "disabled"?

A disabled field is, well, disabled - why should I submit something that is disabled?
A read only field on the other hand is different.
Are you sure that the other fields are disabled and not read only?

I'm saying this because I know this behaviour since the first license I bought and I am not aware of any change.

Sorry if you felt offended maybe - but I did provided a reason - saying "RTFM" without providing a reason is indeed considered rude, if you provide one it is not.

D
druck281 author 3/19/2024

Maybe my original post should have been more clear. I had read what you quoted from the manual before making the post. Afterwards, I had two questions...

  1. If the field value already was in the database, and disabled fields are not submitted with the form, why is the value in the database different after the record was updated? I didn't want it submitted, I wanted the value left unchanged.
  2. Why did one field change and the other did not? I would think identical code applied to two adjacent fields on the same page would behave identically.

If you want to call me offended, so be it. For curiosity, I searched the forum and RTFM has appeared in 11 posts in 20 years. If you thought my question here was ridiculous enought to deserve RTFM, let me caution you not to join the PHPR Facebook group. Your head may explode.

admin 3/19/2024

I don't know what exactly is happening there but if it only happens for some of the fields, there must be some other configuration or code involved. I'd try to figure out what might be different for that specific field.