简体   繁体   English

Expression Engine SafeCracker格式Datepicker

[英]Expression Engine SafeCracker Format Datepicker

Hi I am making a form in expression engine using safecracker and one of my fields called "date of birth" uses the date field type. 嗨我正在使用safecracker在表达式引擎中创建一个表单,我的一个名为“date of birth”的字段使用日期字段类型。 The jQuery datapicker is being automatically added by expression engine but I can't see how to add any of the options or formatting I would normally add to datepicker when making a field of this type. jQuery数据导航器正在由表达式引擎自动添加,但我无法看到如何添加任何选项或格式,我通常会在创建此类型的字段时添加到datepicker。

My normal code: 我的正常代码:

 $(function() {
    $( "#datepicker" ).datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'dd/mm/yy',
        maxDate: new Date()
    });
 });

The only option I can think of is to make this field a text input and add the datepicker myself in the template but this would remove EE's date validation that it performs on this field type. 我能想到的唯一选择是将此字段作为文本输入并在模板中自己添加日期选择器,但这将删除它对此字段类型执行的EE的日期验证。

Is there anyway to add additional datepicker options to this field type? 无论如何还要为此字段类型添加额外的datepicker选项吗?

Well, you can set datepicker="no" in your Safecracker tag , then add your javascript manually. 好吧,你可以在Safecracker标签中设置datepicker="no" ,然后手动添加你的javascript。 However: you can't use your custom format as you show above - for the input to validate as a native EE date field, it must use the datePicker format yy-mm-dd , plus the current time in the format HH:MM AM/PM - which the datePicker doesn't do natively. 但是:您无法使用上面显示的自定义格式 - 要将输入验证为本机EE日期字段,它必须使用datePicker格式yy-mm-dd加上当前时间格式为HH:MM AM/PM - datePicker本身不做的。 ( See this post by one of EE's developers for how they do this.) 请参阅EE的开发人员之一 ,了解他们如何做到这一点。)

An alternative would be to instead use the EEvent Helper date field, because it does not require the time portion to validate (though it too requires yy-mm-dd ). 另一种方法是使用EEvent Helper日期字段,因为它不需要时间部分来验证(尽管它也需要yy-mm-dd )。 However, datepicker="no" only affects native date fields, so you'd instead have to set safecracker_head="no" - but then you'll also lose any javascript or CSS required by other fieldtypes in your form. 但是, datepicker="no"仅影响本机日期字段,因此您必须设置safecracker_head="no" - 但是您还将丢失表单中其他字段类型所需的任何javascript或CSS。

Re: using a plain text field: in addition to the validation issue, your data would then be stored as whatever is input (mm/dd/yy), instead being converted a timestamp, which is far more useful and portable. Re:使用纯文本字段:除了验证问题之外,您的数据将被存储为输入的任何内容(mm / dd / yy),而不是转换为时间戳,这更加实用和便携。

The only true solution is to write your own date fieldtype for this. 唯一真正的解决方案是为此编写自己的日期字段类型。 Wouldn't be very difficult. 不会很困难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM