Hey all,
I'm making a booking calendar for a rental house and I'm trying to make a selectable calendar update two form fields after selection. I want users to be able to drag across available days and populate the start and end date of my form. This is what I have so far:
<script type='text/javascript'>
$(document).ready(function() {
$('#calendar').fullCalendar({
events: "bookings/feed",
selectable: true,
unselectAuto: false,
select: function(startDate, endDate, allDay, jsEvent, view) {
**I just don't know what to put here to edit the inputs bolded below**
}
});
});
</script>
<div style="width: 500px;"><div id="calendar"></div></div>
<div id="eventdata"></div>
<div id="form">
<?php echo $form->create('Booking'); ?>
**<?php echo $form->input('start', array( 'label' => 'Check In:', 'type' =>'text')); ?>
<?php echo $form->input('end', array( 'label' => 'Check Out:', 'type' =>'text')); ?>**
<?php echo $form->input('firstName'); ?>
<?php echo $form->input('lastName'); ?>
</div>
Cheers!
Solved! The following passes the Start and End dates to the form.
select: function(startDate, endDate) {
$( '#BookingStart' ).val(startDate)
$( '#BookingEnd' ).val(endDate)
}
The code in your question didn't paste correctly, but in general to change the input value in jQuery you can do $( '#id_name' ).val( 'new value' ). CakePHP assigns form field ids with the pattern ModelField so the ids you need should be "BookingStart" and "BookingEnd" (you can verify by looking at the HTML source). You can also give the fields any id you want with 'id' => 'foo' option.
Related
i wish to display default time as 9:00 am in ctp time dropdown. Following is my ctp code:
<?php
echo $this->Form->input('Rideoffer.DepartureTime', array(
'type' => 'time',
'interval' => 5
));
?>
how do i do that?
Use the 'selected' option
<?php
echo $this->Form->input('Rideoffer.DepartureTime', array(
'type' => 'time',
'interval' => 5,
'selected' => '09:00:00',
));
?>
The best way to set default data is using the controller (and only if not posted):
if (!$this->request->is('post')) {
$this->request->data['Rideoffer']['DepartureTime'] = '09:00:00';
}
see http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#common-options
This works in all form elements.
"selected", "value", "checked" and other hardcoded attributes for the form directly usually break the form after an unsuccessful post (if the form contains validation errors): it loses all the entered data and reset them to the value it was before which is usually quite annoying for the frontend user.
see http://www.dereuromark.de/2010/06/23/working-with-forms/
I am trying to transfer a value automatically from selection input area to another input area when the selection input has changed. But I cannot. Please help me. The code is here:
<?php
echo $this->Form->input('treatment',
array('options' => $types, 'id' => 'treatment_foo'));
echo $this->Form->input('fee', array('id' => 'fee_foo'');
echo $this->Js->get('#treatment_foo')->event('change',
$this->Js->request(
array(
'update' => '#fee_foo',
'dataExpression' => true,
'data' => '10'))
);
?>
Just use some JQuery
$(document).ready(function() {
$('#treatment_foo').change(function() {
$('#fee_foo').val($('#treatment_foo').val());
});
});
I'm creating a form and want to use multiple fieldsets and legends, is this possible using the form helper?
My form so far -
echo $this->Form->create('PatientCase');
echo $this->Form->inputs(array(
'legend' => 'Patient Details',
...
));
echo $this->Form->end('Save Patient Case');
If you use Form::inputs(), CakePHP will automatically wrap the fields in a fieldset:
echo $this->Form->inputs(array(
'legend'=>'Login',
'User.username',
'User.password'
));
Will produce:
<fieldset>
<legend>Login</legend>
<div class='input text'>...</div>
<div class='input password'>...</div>
</fieldset>
if you set 'fieldset'=>false in your inputs array, cake will suppress field fieldset markup.
You can also use (as also suggested by #kical) before and after to insert the fieldset markup - this makes your code a little less intuative:
echo $this->Form->input('User.username', array(
'before'=>'<fieldset><legend>Login</legend>'
));
echo $this->Form->input('User.password', array(
'after'=>'</fieldset>'
));
You can also manually insert the fieldset markup (handy if you want to customise the fieldset markup or create fieldsets within fieldsets:
<fieldset>
<legend>Login</legend>
<?php
echo $this->Form->input('User.username');
echo $this->Form->input('User.password');
?>
</fieldset>
See API: http://api.cakephp.org/class/form-helper#method-FormHelperinput
Mainly params like: before, after, between or just format
I'm using the Form helper to generate a label:
$this->Form->label('Contact.name', 'Name');
Which generates the following:
<label for="ContactName">Name</label>
Is it possible to generate the following using the helper:
<label for="ContactName"><span class="mandatory">*</span> Name</label>
Whilst I can manually write the html for the above it becomes a little more difficult when I am using the input method where a label is automatically generated.
For example:
$this->Form->input('Contact.forename',array('div' =>false,
'label' => array(
text'=> 'First Name',class =>'myclass'),
'class' => 'input','size' => '25' ,'tabindex' => '1'));
Is this possible in cake or do I have to manually inject the html using javascript when the page loads? Which I would think is rather ugly.
If you are using model validation for the mandatory fields then cakephp automatically applies '*' on the Label else you can use the helper as follows-
echo $this->Form->label('name', '<span class="mandatory">*</span> Name');
If you don't want the labels to generate automatically you can use "label => false" while using the helper.
echo $this->Form->input('Contact.forename',array('label' =>false));
Not sure CakePHP supports that (and it would get a bit messy anyway). The simplest solution I can think of is to assign a "mandatory" class to the label via the form helper:
$this->Form->label('User.name', 'Your username', array('class'=>'mandatory'));
Which produces something like:
<label class="mandatory" for="ContactName">Name</label>
Then the rest is done purely in CSS:
label.mandatory:after {
content: ' *';
color: red;
display: inline;
}
Avoids having any additional HTML.
I know this is old, but maybe someone with Cakephp 3 is having the same problem. This is what fixed it for me, without any inlinecode.
<?php
echo $this->Form->input(
'renovate_old',
[
'type' => 'checkbox',
'label' => ['text' => __('Alte Wohnung'), 'class' => 'moCheckLabel']
]); ?>
So you can name your label and use the Databasefield to write.
you can do it simple by
echo $this->Form->input('whatever', array('between'=>'<label for="ContactName"><span class="mandatory">*</span> Name</label>','label'=>false));
I have a form and i have ended it using,
echo $this->Form->end('Login');
However, i can't seem to assign it an id or class to style it and be able to reference it with jquery. Also,I want to style it with a picture and the picture has the text already in so i need the buttons value to be empty but i can't manage that either...
Any Help?
Many Thanks, Chris
***Note - this is the html it generates;
<div class="submit"><input type="submit" value="Login"/></div>
Ideally i would like to remove the div aswell but its not a necessity.
here's the solution:
$options = array
(
'label' => 'Update',
'value' => 'Update!',
'id' => 'blabla',
'div' => array(
'class' => 'glass-pill',
)
);
echo $this->Form->end($options);
Cheers! =)