[SOLVED] Birthday element not displaying in correct format in custom details template

chozma

Member
Hi guys,

I've got a weird issue with a birthday element. I'm sure this used to work but for some reason it isn't anymore... But then again maybe I am going mad. It wouldn't be the first time that building sites has sent me mad. :eek:

So... the issue is quite straightforward - I have a birthday element in a form. It displays and saves fine in the form. But when I go to use that element in a custom details template it is spitting out a weird date.

I can see that in PHPMyAdmin the date is stored as I would expect and I attach a screenshot of a var_dump of the element in question. You can see that element_raw is exactly what I see in PHPMyAdmin so that's good. But element_ro and value are 'wonky'!

I have also attached a screenshot of the settings for this element. Perhaps it is the translation of the raw date into the format required that is going wrong?

Any ideas?

Thanks as always for your excellent support, :D

Hannah
 

Attachments

  • birthday_list_settings.PNG
    birthday_list_settings.PNG
    15 KB · Views: 273
  • birthday_var_dump.PNG
    birthday_var_dump.PNG
    72.2 KB · Views: 161
I just tested in a standard template, and can't replicate your issue.

Can you just try it in an out-of-box template, just to make sure it's not an issue with your custom one?

And are you sure you are running latest github for it? Rob made some layout changes recently.

-- hugh
 
Ok, just tested it in the bootstrap template and the display formatting is still weird. See attached screenshot.

I did update my Fabrik version on Monday - when did Rob make changes?
 

Attachments

  • dob.PNG
    dob.PNG
    119.6 KB · Views: 154
Not sure when, I'm not at my puter right now. Check github. Navigate to the plugin folder, check the history.

Sent from my HTC One using Tapatalk
 
Ok, no probs. Did have a look at GitHub wasn't sure which layout changes to look for. The birthday element hasn't been updated for 16 days.

Just to be sure though I am doing an update right now. Will report back in a few hours when it's done and will let you know what I find.
 
Sorry to be the bearer of bad news but after an update to the latest version it still does the same weird thing. But the date does display ok on in the list view.
 
AH! I've just had a brainwave about what the problem might be here... And guess what, I reckon its something silly I have done... :oops:

My users have asked me that when they create an animal, for its birthdate the default value of the day and month should be the first Sept and the year to be unset. This is because the majority of animals are born around this time in NZ and it's easier for them to have this as the starting point.

So in order to do this I have added a php plugin to the form set to kick in onLoad (before the form is loaded) using the following code:
Code:
$formModel->data['app_animal___dob']='0000-09-01';

I've just realised that the dates in my details template are setting themselves to this.

So, firstly, would you expect a form plugin to affect details data? I'm guessing you intend this to be the case.

So, secondly, could you suggest how I could implement this request better? Or is it not poss?

Thanks, Hannah x
 
I really don't know what to tell ya. I have a test setup exactly like yours, same detail format, same date ... it works fine.

Is your column in the database correct? It should be DATE, not a DATETIME.

-- hugh
 
Ah HAH!

Do you have the plugin set to "On edit"? If so, that's probably a little booboo on our part.

So do this ...

Code:
if ($formModel->isEditable()) {
   $formModel->data['app_animal___dob']='0000-09-01';
}
[code]

   -- hugh
 
Awesome, nice one Hugh. That seems to be working, the dates are behaving as I need. :D

One question though, what does this line actually do:
Code:
$formModel->isEditable()

Does it figure out if this is a new form eg creating a record.

Could be handy in lots of other places where I've asked if there is an id for a record or not. If not then I have decided the user is creating a new record. This looks to be a much neater solution.

Thanks, Han
x
 
hi
It tells you if you are viewing the form as a form :S - ie. you have access to the fields and can submit the form, or if you are viewing the details view of the form.

If you want to know if it's a new record use the following:
PHP:
if ($formModel->isNewRecord()) {
 // you are creating a new record;
}
 
Wicked! Thanks Rob, that's very handy, totally makes sense! I love you guys, you're always so helpful! :D
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top