Dynamic default value (now) possible?

Jump to: navigation, search

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=2012/02/29' in the form definition does not work, since the #time parser functions does not get evaluated.

Patrick Nagel13:48, 9 March 2011

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.

F.trott20:35, 9 March 2011

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.

Yaron Koren16:00, 11 March 2011

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.trott22:49, 11 March 2011
 
 

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.

F.trott22:57, 15 March 2011

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

213.33.22.12221:50, 8 August 2011

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?

F.trott07:34, 9 August 2011

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.

   Thorncrag  19:12, 10 October 2011

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 "}} }}}").

Yaron Koren21:12, 10 October 2011
 
 
 
 
 
Personal tools

Variants
Actions
Navigation
Support
Download
Development
Communication
Toolbox