cant set default options dropdown box - php

I have populated a dropdown box with data and I can select from a list.I cant seem to set the option on to the selected value.I select a value and I want the drop down box to have the last selected value display instead of resetting to the 1st option in the list. I have tried selected,default with and without numbers.
public function admin_list($tutorId=0,$paycycleId=0) {
if (isset($this->request->data['tutor'])) {
debug($this->request->data['TimeSheet']['tutor']);
$tutorId=$this->request->data['TimeSheet']['tutor'];
return $this->redirect(array('action' => 'admin_list',$tutorId,$paycycleId));
}//isset
view////
echo $this->Form->input('paycycle', array('label' => 'Pay Cycle Period',
'empty' =>array(0 => 'choose'), 'options' => $pcycle,'default'=>2 ));
echo $this->Form->submit('Select a Pay Cycle', array('name'=>'paycycle'));
echo $this->Form->end();

Per the detailed instructions in the CakePHP Book:
Set ‘selected’ to the value of the item you wish to be selected by default when the input is rendered

Related

How to create dynamically disable a single check box of checkboxlist in YII

In a form, I have checkboxlist which has two check box (Male and Female)
User can select both of them or any of them. And values are getting save in DB.
When we populate it from DB then I want to do like if male was selected then it should select Male checkbox and disable the Female checkbox or vice versa.
The code in my View file is:
<?php if(isset($model['gender'])){
$data = $model['gender'];
if (isset($data)) {
if($data == 0)
$htmlOptions = array(
'0' => array('label'=>'MALE'),
'1' => array('disabled'=>'disabled','label'=>'FEMALE'),);
}
if($data == 1){
$htmlOptions = array(
'0' => array('disabled'=>'disabled','label'=>'MALE', ),
'1' => array('label'=>'FEMALE'),);
}
}
echo $form->checkBoxList($model, 'gender', $htmlOptions); ?>
Problem is when I am populating it is selecting the one,I selected while saving but not disabling the other one.
For this you have to use javascript because there is no way you can handle it only with PHP. Now I don't know that much JS, but the steps are easy:
Get the checkbox id's
check which one is selected
disable the other one with innerHTML in JS.
Here you have an example on how you disable checkboxes in JS
Just so you know, the JS should be placed inside the view.

Date field do not display dropdown in popup of SugarCRM

Hy Guys!
I am facing a problem regarding datetime field display in Popup. If i add a datetime field to Advanced Search of ProspectLists it get displayed as shown below and works perfectly:
in the custom modules ProspectLists searchdefs advanced_search array it is defined as :
array (
'type' => 'datetime',
'label' => 'LBL_DATE_ENTERED',
'width' => '10%',
'default' => true,
'name' => 'date_entered', ),
but when i try to select a ProspectList from a Prospect List subpanel in Campaigns, the popup that gets displayed render the date field with out dropdown as shown below:
The other problem is this that when i perform search from popup for a specific date it displays nothing.
I am using SugarCRM CE 6.5.11.
Any idea how to display dropdown with date field.?
In method SugarFieldBase::isRangeSearchView you should check condition
$_REQUEST['action']!='Popup'
File include/SugarFields/Fields/Base/SugarFieldBase.php
I remove it from conditions.
protected function isRangeSearchView($vardef)
{
//return !empty($vardef['enable_range_search']) && !empty($_REQUEST['action']) && $_REQUEST['action']!='Popup';
return !empty($vardef['enable_range_search']) && !empty($_REQUEST['action']);
}
I think what you're looking for is the "Ranged Search" attribute.
You can enable it in studio by going to the custom field and checking the "Enable Range Search" checkbox.
Or, you can edit the custom/modules/{module}/metadata/SearchFields.php and add the following to the field in question:
'enable_range_search' => true

CakePHP 2.x: date input with empty option/values

I have a date input and I wish to have the first option empty or blank. That way the user will have to select something, if not, validation will pick it up.
By default today's date preselected on load. I have managed to input a blank value but I cannot get it as the selected option.
echo $this->Form->input('date_of_birth', array('empty' => ''));
You should use boolean on empty attribute:
echo $this->Form->input('date_of_birth', array('empty' => true));

cakephp select box with recursive 2

I have Tarifs, each tarif hasMany Price and Price also belongsTo UserGroup. So basically prices change when user's group is changed - doesn't matter that much.
The view looks like this
<?php echo $this->Form->create('Tarif');?>
...
$i=0;
foreach ($this->data['Price'] as $price) {
echo "<tr><td>".$this->Form->input("Price.$i.price", array('label' => false))."</td>";
echo "<td>".$this->Form->input("Price.$i.currency", array('label' => false))."</td>";
echo "<td>".$this->Form->input("Price.$i.UserGroup.id", array('label' => false))."</td>";
...
And I need the UserGroup.id input to display as a select, where each option displays group name and has its id as value. The user_group_id values are fine, but the are displayed in a text input. I've tried $this->Form->select and $this->Form->input(...,'type'=>'select') but both of them provided select boxes with no options.
How do I set the input to do what I want?
Thanks
In your controller, you need to add:
$user_groups = $this->UserGroup->find('list');
$this->set(compact('user_groups');
Then in the view, you setup the drop down like:
<?php echo $this->Form->input('user_group', array('options' => $user_groups)); ?>
You can then add $user_groups as an option to any Form->input and it will become a dropdown when using:
array('options' => $user_groups)

how to set an option for form->input( 'multiple'=>'checkbox')

i plan to set a checkbox with selected option in my form.
but i am unable to show my checkbox content in the form, i cant see any value instead of just a box for me to select.
how to show value while i using checkbox? i able to show my value while i using select.
this is in a HABTM model. any hints?
here is my selection code.
input('User',array('label'
=> 'Select Related Potential',
'multiple'=>'checkbox',
//'options' => $users,
'legend'=>$users,
//'value'=>$users,
//'id'=>$ownUserId,
'default'=>$ownUserId,
'style'=>'width:200px;height:100px',
'selected' => $ownUserId, )); ?>
This may be relevant:
You cannot use default to check a checkbox - instead you might set the value in $this->data in your controller, $form->data in your view, or set the input option checked to true.
For example:
// in Controller
$this->data['Model']['field'] = true;
Causes the field to have the value true, which will result in a checked checkbox for this field.
Or:
$form->input('Model.field', array('checked' => true));
Always checks the checkbox.
Or:
$form->input('Model.field', array(
'checked' => ($this->data['Model']['field'] == 'xxx')
));
Dynamically sets the checkbox based on whether $this->data['Model']['field'] is 'xxx' or not.
Sorry, completely misunderstood the question.
Did you find your users via list? The options array needs to be in a particular format, a normal find() won't do that.

Categories