Hi everyone i need your help.
I put dates in Jquery in my form with the id:
twig :
{{ form_label(Form.date, 'Date') }}
{{ form_widget(Form.date, {'id': 'datejquery', 'attr': {'class' :'form-control'}}) }}
formType :
$builder->add('date', DateType::class, ['label' => 'Date', 'widget' => 'single_text', 'html5' => false, 'format' => 'dd/MM/yyyy']);
The code works with 'format' => 'dd/MM/yyyy'
But the display of the datepicker no longer works when I click on the form fields.
I just have the date that appears in the input but I don't have the calendar display...
When : {'class' :'js-datepicker'}})
display empty calendar
Related
I have following code in my view file:
<?= $this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $model,
'attribute' => 'time',
'language' => 'ru',
'htmlOptions' => array(
'size' => '10',
'class' => 'form-control form_empty centered date',
),
'options' => array(
'dateFormat' => 'dd/mm/yy',
'showOn' => 'focus',
'showOtherMonths' => true,
'selectOtherMonths' => true,
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
'closeText' => Yii::t('ablock', 'Очистить'),
'beforeShow' => 'js:
function( input ) {
setTimeout(function() {
var clearButton = $(input ).datepicker( "widget" ).find( ".ui-datepicker-close" );
clearButton.unbind("click").bind("click",function(){ $.datepicker._clearDate( input );});
}, 1 )}',
),
),
true) ?>
I used this code in order to allow user to enter date. However, it is accepting 0 values. For example, if user enters incomplete date such as 0d/mm/yyyy (which is incorret date), it will accept it as true. I need to not allow, if user enters wrong value. How can I do it?
I haven't found any params for accepting only complete dates. Suggested workarounds:
AJAX validation for the date field in your model
disable field input, so the user is limited to the datepicker
perform validation via overriding date method (see example: https://stackoverflow.com/a/21898124/5992898)
I'm developing a small app with CakePHP and I need to save a startdate and an enddate for an event. I went with the Bootstrap Daterangepicker to let users visually input the dates.
In my add.ctp view I have two fields:
<div class="form-group">
<?php echo $this->Form->input('start', array(
'class' => 'form-control',
'type' => 'text',
'id' => 'start',
'name' => 'start',
'data-mask')); ?>
</div><!-- .form-group -->
<div class="form-group">
<?php echo $this->Form->input('end', array(
'class' => 'form-control',
'type' => 'text',
'id' => 'end',
'name' => 'end',
'data-mask')); ?>
</div>
And the Javascript that controls the inputs:
<script type="text/javascript">
$(function() {
$('input[name="start"]').daterangepicker({
timePicker24Hour: true,
singleDatePicker: true,
timePicker: false,
timePickerIncrement: 30,
locale: {
format: 'YYYY-MM-DD HH:mm:ss'
}
});
$('input[name="end"]').daterangepicker({
timePicker24Hour: true,
singleDatePicker: true,
timePicker: false,
timePickerIncrement: 30,
locale: {
format: 'YYYY-MM-DD HH:mm:ss'
}
});
});
</script>
The picker works just fine, it updates the field values properly, but when I attempt to save the form, the start field gets written to the database as follows:
start 0000-00-00 00:00:00
end (null)
The form data for the start and end fields saves properly if I'm reverting to the default configuration of the fields.
Any clue as to where I'm failing would be highly appreciated.
try something like this
$correctdate = date("Y-m-d j:h:m",strtotime($yourdate));
It's not a great peace of code, but it should help to go further in the right direction.
We take this string and make a timestamp out of it. Then we change it to a proper datetime value.
Okay, so I was passing text to a datetime field and the save operation failed. In order to fix this I had to convert the strings to the proper type by processing it in the beforeSave() function of the model.
Here is the code that worked for me:
public function beforeSave($options = array()) {
if (!empty($this->data['Task']['start']) && !empty($this->data['Task']['end'])) {
$this->data['Task']['start'] = $this->dateFormatBeforeSave($this->data['Task']['start']);
$this->data['Task']['end'] = $this->dateFormatBeforeSave($this->data['Task']['end']);
}
return true;
}
public function dateFormatBeforeSave($dateString) {
return date('Y-m-d h:m:s', strtotime($dateString));
}
I want to get a specific value of drowpdown list using jquery and symfony
my code in formType given as follow
->add(
'predefinedMessage',
'entity',
array(
'empty_value' => 'Ajouter un message Prédéfini',
'class' => 'ACMBundle:Message',
'property' => 'name',
'multiple' => false,
'error_bubbling' => true,
'required' => false,
'query_builder' => function (EntityRepository $er) use ($user) {
return $er->createQueryBuilder('u')
->where('u.user = :user')
->setParameter('user', $user);
},
)
)
the entity Message has many fields: id, name, message, userid
I have a text area in my twig
{{ form_widget(form.message,{ 'attr': {'maxlength': '50','placeholder':'placeholder.message.message'|trans} }) }}
in my jquery
<script>
$('#add').click(function(){
var text="{{form.predefinedMessage.vars.data.message }}";
$('#Pushtype_message').val(text);
});
the value of message added to the text area, but when I select the other option, the value in the text area still the same.
consider I have an entity message which contain two line data
id:1 ,userid: 1 , name: message1, message: first message
id:2, userid: 2 , name:message2, message : second message
This is how data is passed.
$items[] = array(
'title' => 'Meeting',
'start' => strtotime('2014-09-09'),
'color' => '#CC0000',
'allDay' => true,
'url' => 'http://anyurl.com'
);
$items[] = array(
'title' => 'Meeting reminder',
'start' => '2014-09-15 05:20:17',
'end' => '2014-09-15 05:30:17',
'color' => 'blue',
);
echo CJSON::encode($items);
Yii::app()->end();
And another issue i have is when enable true as below, it says
'editable'=>'true',
'selectable' => true,
Property "EFullCalendar.editable" is not defined.
Property "EFullCalendar.selectable" is not defined.
Here is how it should work exactly, http://fullcalendar.io/js/fullcalendar-2.1.1/demos/external-dragging.html
If all events are being displayed as All Day, make sure that you don't have allDayDefault set to true (take a look at the docs).
For your second issue, make sure editable is true (boolean instead of string). If it still doesn't work, please include the javascript where you set the default options for fullCalendar.
I'm using Laravel 4. I'm having some problem. I have a users table with fields like. State, Region, Area and City, they are all in string (varchar).
Now, I have my "Edit Users" page. In edit users how can I display the users info ing State, Region etc. in a Select Dropdown? Here's my code.
{{ Form::select('state', array(
'' => 'Choose One', 1 => 'Luzon', 2 => 'Visayas', 3 => 'Mindanao'),
null,
array('class' => 'selectpicker',
'id' => 'state',
'data-live-search' => 'true',
'onchange' => 'document.getElementById("state2").value=this.options[this.selectedIndex].text'
));
}}
How can I make a value for that specific user already appeared or selected in the dropdown?
Thanks!
See if this works for you:
$states = array( 'Choose One', 'Luzon', 'Visayas', 'Mindanao' );
{{ Form::select('state',
$states,
array_search($user->State, $states ), // default value
array(
'class' => 'selectpicker',
'id' => 'state',
'data-live-search' => 'true',
'onchange' => 'document.getElementById("state2").value=this.options[this.selectedIndex].text'
));
}}