CJuiAutoComplete submit selected value - php

I try to get the selected value from dropdown, but it only takes the written value.
How can I take the selected value?
$this->widget('zii.widgets.jui.CJuiAutoComplete',array(
'id' => 'autosuggest_name',
'name' => 'model',
'options' => array('minLength'=>'1'),
'source' => $this->createUrl("advertisements/autocompleteBoatModels"),
'htmlOptions'=> array(
'maxlength' => 30
),
'options' => array(
'delay' => 100,
'showAnim' => 'fold',
'select' => 'js:function(event,ui){
$("#hmodel").val(ui.item.model_id);
$(event.target.form).submit();
}',
),
));
I've tried this, but it doesn't work
$("#hmodel").val(ui.item.model_id).submit
Where is the error :)
thank you

Make ajax call instead of submit
'select'=>'js:function(event, ui) {
$.ajax({
type:"POST",
url: "/your/url",
data: {selected:ui.item.id},
success:function(data) {}
});

Related

How do i get xeditable's content in js

I have below code of xeditable:
$this->widget('editable_ori.Editable', array(
'url' => $this->createUrl('index'),
'pk' => Yii::app()->user->id,
'name' => 'index',
'type' => 'text',
'text' => $data,
'placement' => 'top',
'showbuttons' => 'bottom',
'send' => 'auto',
));
I would like to get the content of this field in my js.
I have tried to grab content of this in js using below code. But its not working
$(".editable editable-click").text;
You are missing a . before the class name editable-click.
You have an extra space after the class name .editable.
The method is text() in jquery not text property to get the text.
Change
$(".editable editable-click").text;
to
$(".editable.editable-click").text()
EDIT
You should call the script after the editable has loaded you can use the event onInit to trigger your javascript function from another file which is dependent on the editable input. For instance, if you have a function
function myFunction(){
//do something
$(".editable.editable-click").text()
//do something more
}
then you should try calling that function from the onInit event like below
$this->widget('editable_ori.Editable', array(
'url' => $this->createUrl('index'),
'pk' => Yii::app()->user->id,
'name' => 'index',
'type' => 'text',
'text' => $data,
'placement' => 'top',
'showbuttons' => 'bottom',
'send' => 'auto',
'onInit' => 'js:function(){myFunction();}'
));
Try using onShown option of editable which will execute as soon as the editable form is shown. You can refer the code below.
$this->widget('editable_ori.Editable', array(
'url' => $this->createUrl('index'),
'pk' => Yii::app()->user->id,
'name' => 'index',
'type' => 'text',
'text' => $data,
'placement' => 'top',
'showbuttons' => 'bottom',
'send' => 'auto',
'onShown' => 'js: function() {
var txtVal=$(this).data("editable").value; // This will hold your textbox value as soon as it opens.
someFunction(txtVal); //Call your JS function with textbox value as parameter.
}'
));
Then in your JS function, you can do so:
<script>
function someFunction(txtVal)
{
//Do anything with editable text box value
}
</script>
Hope this helps you.

How to call ajax through Bootstrap button in yii

I want to use Ajax through bootstrap button in Yii, and want to pass textfield values though that Ajax call.
here's the button code, where should i put the Ajax code for this button.
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'button', 'label'=>'ADD')); ?>
try this
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'button', 'label'=>'ADD',
'ajaxOptions' => array(
'type' => 'Post',
'url' => $this->createURL('url'),
'data' => Yii::app()->request->csrfTokenName."=".Yii::app()->request->getCsrfToken()."&action=cancel",
'success'=>"js:function(vals){
}",
)
)); ?>
another eg:
$this->widget('bootstrap.widgets.TbButton', array(
'buttonType' => 'ajaxButton',
'label' => 'Label Here',
'type' => 'danger',
'icon' => 'play white',
...
'ajaxOptions' => array(
'success' => '...',
'error' => '...',
'beforeSend' => '...',
)
));

Yii - what to pass as an argument when key-value pair is used in Yii extension ext.combobox.EJuiComboBox

Now , I created two dropdownlists (min and max) using the below code.
<?php
$this->widget('ext.combobox.EJuiComboBox', array(
'model' => $model,
'attribute' => 'min', 'data'=>array('100000.0'=>'1lakh','200000.0'=>'2lakh','300000.0'=>'3lakh','400000.0'=>'4lakh'),
'assoc'=>true,
'options' => array(
'onSelect' => 'cost_change(item.value);',
'allowText' => false,
),
'htmlOptions' => array('placeholder' => 'Min Cost', 'style'=>'width:30px'),
));
?>
<?php
$this->widget('ext.combobox.EJuiComboBox', array(
'model' => $model,
'attribute' => 'max',
'data' => array('300000.0'=>'3lakh','400000.0'=>'4lakh','500000.0'=>'5lakh','600000.0'=>'6lakh'),
'options' => array(
'allowText' => false,
),
'htmlOptions' => array('placeholder' => 'Max Cost', 'style'=>'width:30px'),
));
?>
I'm calling a script on selecting the min value which in turn calls the script
<script>
function cost_change(price) {
var value = price;
console.log("value",value);
jQuery('#max').html( jQuery('#SearchForm_min_cost_select').html())
var toKeep = jQuery('#max').filter( function( ) {
return parseInt(this.value) > parseInt( value);
} );
console.log("to keep",toKeep);
jQuery('#max').html(toKeep);
}
</script>
Now my problem is when I select 1lakh as min value in dropdown, 1lakh is passed to script instead of 100000.0. What should I pass to the function cost_change to pass 100000.0 instead of 1lakh.
The default combobox doesn't support associative arrays. However, there's a fix for this at https://github.com/kanyuga/yii-combobox/blob/master/EJuiComboBox.php
EDIT
Also I stopped using this extension and use http://www.yiiframework.com/extension/select2/ instead.

How to get current selection value from cake php FormHelper

I need to modify some code in cakePHP and the last thing that is holding me still is my inability to get current value from input form and send it to my jquery script.
The forms look like this:
<?php echo $this->Form->input('country', array('options' => $countriesOption, 'onchange' => 'getHotels(this.value, $(\'showSingleInput\').checked);', 'style' => 'margin: 10px;', 'div' => false, 'label' => false, 'error' => 'false', 'hiddenField' => false, 'id' => 'countryInput')); ?>
<?php
if($regionOption != null){
echo $this->Form->input('region', array('options' => $regionOption, 'onchange' => 'getHotelsInRegion(this.value,this.value, $(\'showSingleInput\').checked);', 'style' => 'margin: 10px;', 'div' => false, 'label' => false, 'error' => 'false', 'hiddenField' => false, 'id' => 'regionInput'));
}?>
The problems is at second input form 'region'.
I need to pass as first value to JQuery method currently selected value from 'country' form input.
And all the hard stuff I need to do is here:
'getHotelsInRegion(this.value,this.value, $(\'showSingleInput\').checked);'
Something like
$('#ModelNameFieldName').change(function() {
alert($(this).val());
});
should to the trick.

Yii datepicker in gridview filter changes format after ajax request

like in the subject. I have a CGridView and Yii's datepicker in one of the filters. I have a format set to yy-mm-dd but after I put the value and the GridView use ajax to adjust the data - format is changed to: dd.mm.yy. Here is my code:
array(
'name' => 'confirmStart',
'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker',
array(
'model' => $model,
'attribute' => 'confirmStart',
'language' => 'pl',
'i18nScriptFile' => 'jquery.ui.datepicker-ja.js',
'htmlOptions' => array(
'id' => 'Projects_confirmStart',
'dateFormat' => 'yy-mm-dd',
),
'defaultOptions' => array( // (#3)
'showOn' => 'focus',
'dateFormat' => 'yy-mm-dd',
'showOtherMonths' => true,
'selectOtherMonths' => true,
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
)
),
true),
),
Don't know if this is gonna solve your problem, but I had some issues when using a datepicker in a CGridView. To solve it I needed to reinstall the datepicker:
In your CGridView:
'afterAjaxUpdate' => 'reinstallDatePicker',
And below the Cgrid View add the following sript:
Yii::app()->clientScript->registerScript('re-install-date-picker', "
function reinstallDatePicker(id, data) {
$('#Projects_confirmStart').datepicker();
}
");
If it still doesn't solve your problem you could try:
Yii::app()->clientScript->registerScript('re-install-date-picker', "
function reinstallDatePicker(id, data) {
$('#Projects_confirmStart').datepicker({ dateFormat: 'yy-mm-dd' });
}
");
or (not sure of the one you should use)
Yii::app()->clientScript->registerScript('re-install-date-picker', "
function reinstallDatePicker(id, data) {
$('#Projects_confirmStart').datepicker('option', 'dateFormat', 'yy-mm-dd');
}
");
Edit:
To put back the date you could try to set the date using javascript:
Yii::app()->clientScript->registerScript('re-install-date-picker', "
function reinstallDatePicker(id, data) {
$('#Projects_confirmStart').datepicker('option', 'dateFormat', 'yy-mm-dd');
var start = $('#Projects_confirmStart').val();
$('#Projects_confirmStart' ).datepicker( 'setDate', start );
}
");
I'm really not sure it will work

Categories