Topic on Extension talk:Semantic Forms Inputs

Dynamic default value (now) possible?

10
Patrick Nagel (talkcontribs)

With SF's input type=date or datetime it's possible to specify 'default=now', and it'll fill in the current time, is this also possible with date(time)picker? 'default=2015/07/10' in the form definition does not work, since the #time parser functions does not get evaluated.

F.trott (talkcontribs)

I'm afraid it is not possible with either of them. The default value is handed down to the input type in the same parameter as the current value, there is no possibility to distinguish between them so I can't decide when to parse and when not. The solution lies with SF here. You might vote on this or this bug or (more effectively) discuss it with Yaron directly.

Yaron Koren (talkcontribs)

It's not clear to me that this requires any change from SF - it might just need a fix in SFI. F.trott and I talked about the issue "offline", but now I don't remember what the conclusion was.

F.trott (talkcontribs)

I do. :)

The point is, SFI could parse the current/default value given as a parameter to the input. But then it would also parse any user input a user might have done earlier. E.g. lets say it would indeed parse the value. Along comes some user thinking that "{{#time:...}}" would be a good thing to put into that field - would result in a valid date after all. This user would fully and rightly expect that "{{#time:...}}" appears verbatim in the page. It even would after the first edit. Then on the second edit the datepicker would parse that string and save it, i.e. it would replace the parser command by a static value.

F.trott (talkcontribs)

Patrick, could you try updating to the last SVN version of SF and using default={{#time:Y/m/d}}? (You will need Extension:ParserFunctions if you don't have it yet.) The "default" parameter should get parsed now. It's still brand new, so any bug reports would be welcome.

213.33.22.122 (talkcontribs)

just tried that, but the date doesn't get parsed inside the form field. I'm using SF 2.2.1, SFI 0.4.2 alpha, parser functions 1.4.0

F.trott (talkcontribs)

Hmm, should work.

What exactly do you specify as the default and what is displayed in the form?

And does it work if you use a different input type, e.g. text?

Thorncrag (talkcontribs)

Using default with the parser worked for me. Remember that if you use a parser within a field declaration make sure it is not the last parameter specified, or if it is, place the 3 field closing curly braces on the next new line, otherwise it will break the field; for example:

  • WRONG:
    {{{field|bulletin_date|mandatory|input type=datetimepicker|default={{#time:Y/m/d}}}}}
  • RIGHT:
    {{{field|bulletin_date|mandatory|default={{#time:Y/m/d}}|input type=datetimepicker}}}
  • RIGHT:

{{{field|bulletin_date|mandatory|input type=datetimepicker|default={{#time:Y/m/d}}
}}}

Cheers.

Yaron Koren (talkcontribs)

That bug is mentioned in the documentation - if it's any simpler, you don't even need a newline, you just need a space (like "}} }}}").

Kghbln (talkcontribs)

Just to add a bit to this. One has to make sure that form definitions are not cached. So if this is in the LocalSettings.php: $sfgCacheFormDefinitions = true; it will have to be removed to make sure that dynamic values can be generated every time a form is used. This also is already mentioned in the documentation.

Reply to "Dynamic default value (now) possible?"