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.
Related
$fieldset->addField('test_connection', 'submit', array(
'label' => Mage::helper('rpos_connect')->__('Test Connection'),
'required' => true,
'value' => 'Test',
'after_element_html' => '',
'tabindex' => 1
));
This is my PHP code to prepare a form with a button in my module block folder.Now I want this to call a function named testAction() in my Controller class.
You can use onclick as follows.
'onclick' => "setLocation('{$this->getUrl('*/controller/action')}')"
I'm trying to change the element value using Jquery but it's not working...
This is my widget where I have my element 'tag' which i want to change it to textField on edit...
$this->widget('EditableGrid', array(
'dataProvider' => $dataProvider->searchbyID($invoice_id),
'template' => '{items}{buttonCreateRow}{pager} ',
'id' => 'InvoiceLine-grid',
'rowTemplate' => $row_template,
'columns' => array(
array(
'class' => 'EditableGridColumn',
'header' => '',
'name' => 'InvoiceLine_{gridNum}_{rowNum}_edit',
'imageurl'=> Yii::app()->request->baseUrl.'/images/update.png',
'tag' => 'button',
'tagHtmlOptions' => array(
'onclick'=>'editline(this)',
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'StentysRef',
'name' => '[{gridNum}][{rowNum}]stentysproductref',
'tag' => 'laabel',
'tagHtmlOptions' => array(
'style'=>'background-color:#FFF;border-color:#FFF',
'onkeyup'=>'stentysref(this)',
'readonly'=>true
)
),
My Jquery is,
(as you can see the removeAttr works but attr doesn't)
function editline(obj){
$("#InvoiceLine_1_"+row+"_stentysproductref").attr("tag","textField");
$("#InvoiceLine_1_"+row+"_stentysproductref").removeAttr("readonly");
}
Use .prop() and removeProp() which is added in jQuery 1.6, as the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior.
function editline(obj){
$("#InvoiceLine_1_"+row+"_stentysproductref").prop("tag","textField");
$("#InvoiceLine_1_"+row+"_stentysproductref").removeProp("readonly");
}
API Doc for .prop()
If you are using EditableGrid widget without pointing AR model, then the row id looks like
$('#_1_'+row+'stentysproductref').
I'll take it into consideration for the future updates. Thank you.
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) {}
});
I would like to reload the form, or preferably just the values, by using 'onChange'. There are several elements in the form that needs to be updated when changing the project id.
$this->addElement('select', 'project_id', array(
'label' => t('Project'),
'multiOptions' => $data,
'filters' => array('Int'),
'value' => 0,
'required' => true,
'disableTranslator' => true,
'validators' => array(),
'onChange' => 'Javascript:window.location.reload(false)'
));
You can change your onChange to call a custom javascript function instead - which will change any fields you need to change, and then submmit the form.
Is the any way, to access model located in $data variable from CButtonColumn?
Below code is not working.
array(
'class' => 'CButtonColumn',
'template' => '{test}',
'buttons' => array(
'test' => array(
'label' => 'Select',
'click' => 'js:function() { <b>alert($data->_id);</b> return false;}',
),
),
),
It is possible to access visible attributes from jquery:
'click'=>'js:function(){alert("first element in cgridview is"+$(this).parent().parent().children(":nth-child(1)").text());}'
The only field where $data is allowed in CButtonColumn class is url, imageUrl and visible. To pass id to the javascript click event you may place such id in the url and grab it from the DOM. This is very rude hack but easy implementation.
array(
'class' => 'CButtonColumn',
'template' => '{test}',
'buttons' => array(
'test' => array(
'label' => 'Select',
/* set id */
'url' => $data->id,
/* retrieve id from this DOM element (jQuery) */
'click' => 'function() { alert( $(this).attr("href"); return false;}',
),
),
),
If you are looking for a more clear coding you could work in CDataColumn class
It looks like _id is a private variable (according to Yii's coding "standards"). You can not access private variables (and methods) outside of an object. Create a getter-method like this in your model:
public function getId() {
return $this->_id;
}
and then change your code to:
array(
'class' => 'CButtonColumn',
'template' => '{test}',
'buttons' => array(
'test' => array(
'label' => 'Select',
'click' => 'js:function() { alert($data->id); return false;}',
),
),
),
You need to customize the CButtonColumn class. Have a look this post:
http://www.yiiframework.com/wiki/714/yii-1-1-cgridview-use-special-variable-data-in-the-options-of-a-button-i-e-evaluate-options-attribute/
You can do that by custom function, as we can derived a $data variable inside it so that we can utilize better php as well as yii itself.
Try like this :
'test' => array(
'label' => 'Select',
'click' => function($data) {
$id = $data->id;
return "js:function() { alert($id); return false;}";
},
),