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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Datefield, DatePicker not displayed when using $Fields.dataFieldByName


Go to End


3 Posts   1006 Views

Avatar
Praveen

Community Member, 49 Posts

1 April 2015 at 11:20pm

Datepicker scripts are loaded after Render . But the event is not triggered when the date-picker is called by field name.

<% if $IncludeFormTag %>
<form $AttributesHTML>
<% end_if %>
<div class="field_wrap">
	$Fields.dataFieldByName(ProfileStatus)
</div>
<% if $IncludeFormTag %>
</form>
<% end_if %>

Thanks
B L Praveen

Avatar
Devlin

Community Member, 344 Posts

2 April 2015 at 4:43am

I noticed that too, but "$Fields.dataFieldByName('ProfileStatus').FieldHolder" works.

Avatar
Praveen

Community Member, 49 Posts

6 April 2015 at 6:42pm

Edited: 06/04/2015 7:05pm

I had to include all the scripts to make this work

			Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
			Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
			Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-ui/jquery-ui.js');

As I don't wanted extra div wrap around the field .Hence not to use FieldHolder

Another way is to include a Bootstrap DatePicker.

		Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
                Requirements::css("thirdparty/datepicker/bootstrap-datepicker.css");
                Requirements::javascript("thirdparty/datepicker/bootstrap-datepicker.js");
               Requirements::customScript("jQuery(document).ready(function($) {$('.field.date .date-bootstrap input.text').datepicker({'format': 'dd/mm/yyyy'});});");


		<div class="field_wrap input-append date-bootstrap">
			$Fields.dataFieldByName(DateOfBirth)
		</div>

Devlin , Thanks you very much.

And also when using $Fields.dataFieldByName how to get field Label.
Currently I am rewriting on the form

<label class="form-label" for="{$FormName}_Email">Email:</label>