Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

$dataFieldByName(MyDateField) - not using calendar


Reply


3 Posts   1170 Views

Avatar
swaiba

Forum Moderator, 1799 Posts

12 October 2010 at 1:44am

Hi,

I want to render a form in a custom way and keep the popup calendar. I am using 2.4.2 and the code for the form is as follows...

public function MyDateForm()
{
   $fields = new FieldSet();

   $dfFrom = new DateField('DateFrom', 'DateFrom');
   $dfFrom->setConfig('showcalendar', true);
   $dfFrom->setLocale('en_GB');
   $dfFrom->setConfig('dateformat', 'YYYY-mm-dd');

   $fields->push($dfFrom);

   $actions = new FieldSet(new FormAction('StartDate', 'StartDate'));
   return new Form($this, "DateForm",$fields,$actions);
}

the calendar popup is not added if I try and customise the form output, can anyone see anything in the later two exaples that would enable it?

does work, but does not allow customisation of the form...

<div id="LeftPane">
   $MyDateForm
</div

does not work

<div id="LeftPane">
   <% control MyDateForm %>
      <form $FormAttributes>
         <fieldset>
            <p>
               $dataFieldByName(DateFrom)
            </p>
            <p class="Actions">
               <% control Actions %>
                  $Field
               <% end_control %>
         </fieldset>
      </form>
   <% end_control %>
</div>

also does not work...

<div id="LeftPane">
   <% control MyDateForm %>
   <form $FormAttributes>
      <fieldset>
         <% control Fields %>
             <p>
               $Title
               <br />
               $Field
            </p>
         <% end_control %>

         <p class="Actions">
            <% control Actions %>
               $Field
            <% end_control %>
         </p>
      </fieldset>
   </form>
   <% end_control %>
</div>

Any help is much appreciated!

Avatar
bartvanirsel

Community Member, 94 Posts

12 October 2010 at 7:47am

Hi,

Is jquery included in your header and is the jscript for the calendar field in your website's sourcecode?

Avatar
swaiba

Forum Moderator, 1799 Posts

12 October 2010 at 10:29pm

Edited: 12/10/2010 10:29pm

Thanks bartvanirsel!

That helped - the following JavaScript is in the $MyDateForm - but not the others...

http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js
http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/i18n/jquery.ui.datepicker-en-GB.min.js
http://localhost/aoa/sapphire/thirdparty/jquery-metadata/jquery.metadata.js?m=1268274558
http://localhost/aoa/sapphire/javascript/DateField.js?m=1278917861

I've had a search for them and they relate to the date field... but I'm struggling to see why one date filed gets created and the other doesn't as it must go through the same code... but that is a great hint, thanks again.