protected $_cast = 'date';
protected $_columnType = 'date';
protected $_columnFormat = 'YYYY-MM-DD';
+ protected $_pickerFormat = 'yyyy-mm-dd';
}
namespace Cubist\Backpack\Magic\Fields;
+use Cubist\Backpack\Facades\App;
+use Illuminate\Support\Facades\Session;
+
class Datetime extends Field
{
protected $_adminType = 'datetime_picker';
protected $_cast = 'datetime';
- protected $pickerOptions = ['format' => 'DD/MM/YYYY HH:mm', 'language' => 'fr'];
+ protected $_pickerFormat = 'yyyy-mm-dd hh:ii';
protected $_databaseType = 'datetime';
protected $_databaseIndex = true;
protected $_columnType = 'datetime';
public function getDefaultAttributes()
{
- return array_merge(parent::getDefaultAttributes(), ['datetime_picker_options' => $this->pickerOptions]);
+ return array_merge(parent::getDefaultAttributes(), ['picker_format' => $this->_pickerFormat]);
+ }
+
+ protected function _postSetAttributes()
+ {
+ parent::_postSetAttributes();
+ $this->setAttributeIfNotSet('datetime_picker_options', $this->_getDatePickerOptions());
+ $this->setAttributeIfNotSet('date_picker_options', $this->_getDatePickerOptions());
+ }
+
+ protected function _getDatePickerOptions()
+ {
+ return ['format' => $this->getAttribute('picker_format'), 'language' => __('fr'), 'todayHighlight' => true];
}
}
{
if (null !== $this->getAttribute('can', null)) {
if (!self::can($this->getAttribute('can'))) {
+ $this->setAttribute('preview', false);
+ $this->setAttribute('filter', false);
+ $this->setAttribute('column', false);
+ $this->setAttribute('auth', false);
+ $this->setAttribute('type', 'noteditable');
+ $this->setAttribute('view_namespace', CubistBackpackServiceProvider::NAMESPACE . '::fields');
+ }
+ }else if (null !== $this->getAttribute('can_hidden', null)) {
+ if (!self::can($this->getAttribute('can_hidden'))) {
$this->setAttribute('preview', false);
$this->setAttribute('filter', false);
$this->setAttribute('column', false);
+@php
+ // if not otherwise specified, the hidden input should take up no space in the form
+ $field['wrapper']['class'] = $field['wrapper']['class'] ?? $field['wrapperAttributes']['class'] ?? "hidden";
+ $v=old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? '';
+ if(!is_string($v)){
+ $v=json_encode($v);
+ }
+@endphp
+
+ <!-- hidden input -->
+@include('crud::fields.inc.wrapper_start')
+<input
+ type="hidden"
+ name="{{ $field['name'] }}"
+ value="{{ $v }}"
+ @include('crud::fields.inc.attributes')
+>
+@include('crud::fields.inc.wrapper_end')