Optional date picker error

yes
image

I’m in edge - normally I see more detail on the error here but it’s blank:

Have your Dev tools open and then submit the form to see the error

What are those 6 errors?

The 6 errors were me submitting the form 6 times :laughing:

I have the dev tools open when I submit but it remains blank.

Really appreciate you looking at this. I’m giving up for tonight and will try again with a clear head in the morning. I’m pretty sure it’s a problem with a date-picker in a form being left blank - I just don’t think Wappler / serverconnect allows it

These are Date fields my friend!!!

It’s explained here exactly where and how to see the detailed error response:

Please follow it and paste the error here.

Thanks @Teodor - I couldn’t find the Fetch/XHR in edge but I have it now:
Just says incorrect date value as suspected:

@famousmag - I already tested changing the datatypes in the parameters and it doesn’t do anything. I think everything is posted as text anyway. The issue only occurs if the date-picker is blank.

It seems the date picker is sending ‘’ which the database is interpreting as not a valid date instead of null or blank

Paste the form code only for these 2 data fields here… The 2 inputs

The error says you can’t save an empty string in a date field in your db as it’s not allowed. Googling this returns many results, for example:

1 Like

Do you mean this? They are identical so here’s only one:

<input class="form-control" id="est_first_pay_date" name="est_first_pay_date" aria-describedby="est_first_pay_date_help" placeholder="Enter some text" type="text" is="dmx-date-picker" dmx-bind:value="first_payment_date.toDate().toISODate()">

fyi - the value is being set via a datastore for page UX reasons, but I’ve tried taking out the value binding and it makes no difference.

In your case you can also insert null as a default value, as an empty string is not allowed. Example:

{{$_POST.est_first_pay_date.default(null)}}
1 Like

OK yes - thank you, this is definitely the issue. The date picker is sending an empty string and the database is not accepting that as blank / null.

Is there a way in Wappler I can convert the empty string to a null value, or change the DB setting? Or if I use the condition column in the insert query, can I say to only insert that field if it is not an empty string?

It sounds like it’s not possible and I need to use workbench or similar to change the settings in the database directly.

Sorry didn’t see this - I’ll give this a try

Teodor gave us the problem explanation…

And a solution

Thank you neighbor!!

1 Like

Unfortunately I don’t think I can use this because the field is part of a subtable (so following this method: Inserting Data in Main and Sub Table using App Connect Form Repeat - Docs / Server-side Components - Wappler Community

Unless there’s somewhere else I can insert it? As it stands, the $Post is the array and the names match the database fields.

Otherwise, I guess I can build the repeat manually

In case others have problems with empty date pickers, I tested writing directly to subtable using this and it worked perfectly.

As far as I can see, I can’t apply it to inserting into a main table and sub-table via a form-repeat though as I can’t edit the $_Post for the fields in the subtable. However, it should work if I manually create a repeat in the server action instead of using the Wappler inbuild shortcut.

Thanks again to you both

Try using the condition option here instead {{$_POST.est_first_pay_date != ''}}

I tried but it didn’t work (still tried to insert the empty string):

Not sure if it’s supposed to be referencing the formrepeat? If I select it in the picker I get this, but I guess I would need to correct [0] for some sort of $index.

$_POST.formRepeatExposures[0].est_first_pay_date!=''

In any case - I can easily make a repeat in the server action and that will definitely work.

Ok i understand the problem, we should improve the sub table insert process and allow some data formatting to be applied @patrick
Meanwhile you can connect to your db with some third party tool like mysql workbench and set the sql_mode to ALLOW_INVALID_DATES

Just to close this off and for anyone reading in future:

I found the best solution was to use a repeat in the server action (to insert to the subtable directly) and not use the main table/ subtable insert process. Reasons being:

  1. I could easily use .default(null) to solve the problem
  2. Changing mysql modes is complicated with a Docker database as it resets to default settings on every restart without manipulating config files
  3. You have more control over the insert process in the subtable e.g. combining data from the form with other sources that perhaps shouldn’t be in the form. For example, userid from the security provider and any associated data from the db that a bad actor could potentially manipulate in the front end

Many many thanks again for the super fast responses and help with this.

2 Likes