Trouble with a null - front end

hi,

have a little trouble checking for null on the front end. I have 2 date fields, these fields only get shown if a certain service is selected. So most the time are not shown and null.

the 2nd date field adds 1 month to the first date field (if the first date field is not null. but it ignores this.

I have this code

<input id="StorageFrom" name="StorageFrom" is="dmx-date-picker" type="text" placeholder="Storage From" class="style7" format="YYYY-MM-DD">

<input id="StorageTo" name="StorageTo" is="dmx-date-picker" type="text" placeholder="Storage to" class="style7" format="YYYY-MM-DD" dmx-bind:value="(StorageFrom.value != 'null').addMonths(1)">

but no matter what I do I always get the default date + 1 month (1970-01-01.

Any ideas what I am doing wrong?
thanks

The key for wrapping code is the ‘backtick’ - if you search online for the location on your keyboard you’ll probably have it. To do a block of code use 3 backticks either side

See here (you could copy and paste from this post too):

thanks. yeah my keyboard oddly doesnt have it, will have to google it and copy paste it, just needs a button on toolbar :wink: thanks for the tip, will edit my post

1 Like

I suspect you might be having problems because the id of the inputs matches the name attribute. Try making it something like
id="inp_StorageFrom" name="StorageFrom"
and then updating the other reference
dmx-bind:value="(inp_StorageFrom.value != 'null').addMonths(1)"

alas no, didn’t make any difference :frowning:

Ah. You have null encapsulated as a string - try removing the speech marks and make it a ternary (otherwise you are trying to use a true/false with the addMonths):

dmx-bind:value="inp_StorageFrom.value?(inp_StorageFrom.value).addMonths(1):null"

thanks, but still no gold medal :wink: same result.

Just tried it with:

<input id="inp_StorageFrom" name="StorageFrom" is="dmx-date-picker" type="text" placeholder="Storage From" class="style7" format="YYYY-MM-DD">

<input id="inp_StorageTo" name="StorageTo" is="dmx-date-picker" type="text" placeholder="Storage to" class="style7" format="YYYY-MM-DD" dmx-bind:value="inp_StorageFrom.value?(inp_StorageFrom.value).addMonths(1):null">

and it works for me

One slight tweak - the date-picker element doesn’t like null as a value so if the first date is empty, it needs to be set to '':

<input id="inp_StorageFrom" name="StorageFrom" is="dmx-date-picker" type="text" placeholder="Storage From" class="style7" format="YYYY-MM-DD">

<input id="inp_StorageTo" name="StorageTo" is="dmx-date-picker" type="text" placeholder="Storage to" class="style7" format="YYYY-MM-DD" dmx-bind:value="inp_StorageFrom.value?(inp_StorageFrom.value).addMonths(1):''">

I appreciate the help, but for me still not working, and i copy pasted your line next to my lines and compared and they are equal. I am doing a DB insert and its the DB field that has the date showing, but, the field I store to is just a text not a date field as it seems date fields cannot be null, but the text field always receives the date 1970

So is your problem that the field doesn’t show the right step on the client-side or that the wrong value is inserted into the DB?

Date fields can be null as long as the column in the table is set up to allow it, but you might also want to make the insert value
{{$_POST.StorageTo.default(null)}}

An empty string will use null instead of the epoch date

that worked :slight_smile: thanks for all the effort, really appreciated