I am using both the client validation and ajax validation for my CActiveForm but both the client and ajax validations are not performing if i remove ajaxvalidation means to false the client validation is happening. can any suggest for the solution here i am posting my code
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'useraccess-form',
'enableClientValidation'=>true,
'enableAjaxValidation'=> true,
'clientOptions' => array(
'validateOnSubmit' => true
),
)); ?>
I got the same problem when tried to set id for feilds via htmlOptions
Check source code of generated page. Compare ids of fields in javascript code with ids in html code
I am included JQuery twice. Need once and with framework.
<?php Yii::app()->getClientScript()->registerCoreScript('jquery'); ?>
Related
What I want to achieve Image! Hi I am working on a module in prestashop. What I want is that there should be a button (any-name: Add new field) in the backoffice-(Module Configuration page the first page that comes when you configure your module) that the user presses and it should add a new input field in the form. This all should be done using the helper classes. How can I achieve that? Some code would be grateful! I have uploaded an image. I have tried it using jQuery and it works but I need this done using helperForms in prestashop! In jQuery if I press the add new field button it adds an input field dynamically but the helper-classes are not used in that case.
Here is a link to the documentation :
http://doc.prestashop.com/display/PS16/Using+the+Helper+classes
the documentation is for PS 1.6 but it should also work with PS 1.7
Here is an example of code that generate a form with Helper Classes :
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Edit carrier'),
'image' => '../img/admin/icon_to_display.gif'
),
'input' => array(
array(
'type' => 'text',
'name' => 'shipping_method',
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right'
)
);
I don’t know if you can use Helper class for custom forms that update custom datas. I’m sure you can use them to update module configuration and prestashop object (customer, etc.)
Helper classes enable you to generate standard HTML elements for the
back office as well as for module configuration pages.
When I use Kartik ExportMenu widget in my code, all dropdown stop working..
Here's a sample of code I am using,
echo ExportMenu::widget([ 'dataProvider' => $dataProvider, 'columns' => $gridColumns ]);
the widget is affecting only that single page, dropdowns on other pages are working..
After some Googling, I found that its conflicting with bootstrap js file.. which I am including in my Asset 'bootstrap.min.js',
if I remove bootstrap.min.js, obviously.. all dropdown should stop working.. but the dropdown on the page I have widget are working..
In my project I need to use both of them...
Is there any solution, anyone can think off??
for that use unset concept in that particular page.
add following lines at the end of your code.
<?php unset($this->assetBundles['yii\bootstrap\BootstrapAsset']); ?>
Add a showColumnSelector to the widget options and assign value true to it. as in:
echo ExportMenu::widget([
'dataProvider' => $dataProvider,
'columns'=>$gridColumn,'showColumnSelector' => \true,
]);
I am trying to display the price based on the selection of product from a drop down.
View contains:
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'plan-form',
'enableAjaxValidation'=>true,
)); ?>
<?php echo $form->dropDownListRow($model, 'plan_id',
$planList, array('id'=>'planid', 'prompt'=>'Select Plan',
'ajax' => array('type'=>'GET',
'url'=> Yii::app()->createUrl('mbr/plan/ajaxGetPrice'),
'update'=>'#price'))); ?>
<div id="price">0.00</div>
<?php $this->endWidget(); ?>
Action:
public function actionAjaxGetPrice()
{
Yii::log("Within AjaxGetPrice");
if (Yii::app()->request->isAjaxRequest)
Yii::log("ajax request");
else
Yii::log("regular request");
//$plan=Plan::model()->findByPk((int) $_GET['plan_id']);
//Yii::log(serializ($plan));
// echo $plan->price;
echo "10";
Yii::app()->end();
}
It is not updating the price. Its not calling the action at all. I looked at the suggestions found in Yiiframework and here and tried those and still no luck.
when I add this to the view
<?php
echo CHtml::ajaxLink(
"Get Price",
Yii::app()->createUrl('mbr/plan/ajaxgetprice'),
array( // ajaxOptions
'type' => 'GET',
'update' => '#price'),
array( //htmlOptions
'href' => Yii::app()->createUrl('mbr/plan/ajaxgetprice')
)
);
?>
I get the response when I click on the link, but it renders a separate page with value "10". I have URLFormat = Path.
What am I doing wrong? Any pointers?
You can also try this as shown
<?php echo CHtml::dropDownList('categories','',
$category,
array('ajax'=>array('type'=>'POST','url'=>CController::createUrl('yourController/GetId'),'update' =>'#data'))
);?>
yourController action
public function actionGetId(){
echo 10;
}
And the div
<div id="data">0.00</div>
I'm not really sure how to do this the Yii way but the following javascript should be useful.
$("#yourdropdownidhere").change(function(){
$.ajax({
url: 'your url here', //(dynamically generated by product item)
type: "get",
success: ajaxSuccessHandler
});
});
function ajaxSuccessHandler(obj) {
$('#price').html(obj);
}
I also suggest sending a JSON object as the response for AJAX requests, so it will have an actual structure. A great blog post on this to check out would be Fully ajax website with Yii
I had the same problem and solved it on the controller that renders the view. If you are using renderPartial assure that the processOutput() option is set to TRUE, otherwise Yii will not attach any Javascript.
If you use render instead of renderPartial it also works.
I am using Tipsy tooltip
in a popup which loads on ajax call. In such case the tooltip css does not work. The widget load the css file but does not work.
Here is my code :
<a id="north-west" href="#" original-title="Click on this">Click me</a>
<?php
$this->widget('application.extensions.tipsy.Tipsy', array(
'trigger' => 'hover',
'items' => array(
array('id' => '#north-west', 'gravity' => 'sw'),
),
));
?>
Usually when you load via ajax you would use 'renderPartial' instead of 'render'. There is one catch though: If you have javascript in it you need to make sure the processOutput parameter is set to TRUE. Basically the call would be:
$this->renderPartial('view', array(<data>), FALSE, TRUE);
Yii would then make sure the javascript is also returned, it normally does not do that with a partial. This is only required for ajax calls where the renderPartial is the only output you do, not for calls to it during a regular request.
CGridView widget is already having view,update,dete option.But i am using CListView widget in my jquery mobile based project, but having problem in creating ajax link for delete option. Not getting idea how to create a ajax delete link in _view.php(view file) and its renderPartial() view file to disappear the bar after successfully deleted plz help thanks in advance. Here is the _view.php file link for edit and delete.
<?php
echo CHtml::link(CHtml::encode($data->id),
array('editmember1', 'id' => $data->id),
array('data-role' => 'button', 'data-icon' => 'star')
);
echo CHtml::link(CHtml::encode($data->id), $this->createUrl('customer/delete', array('id' => $data->id)),
array(
// for htmlOptions
'onclick' => ' {' . CHtml::ajax(array(
'beforeSend' => 'js:function(){if(confirm("Are you sure you want to delete?"))return true;else return false;}',
'success' => "js:function(html){ alert('removed'); }")) .
'return false;}', // returning false prevents the default navigation to another url on a new page
'class' => 'delete-icon',
'id' => 'x' . $data->id)
);
?>
This is happening because:
The correct action is not being called, because you have not set the url property of jQuery.ajax(). You should know that Yii's CHtml::ajax is built on top of jQuery's ajax. So you can add :
CHtml::ajax(array(
...
'url'=>$this->createUrl('customer/delete', array('id' => $data->id,'ajax'=>'delete')),
...
))
Also in the url i'm passing an ajax parameter so that the action knows that it's an ajax request explicitly.
Then the controller action by default(i.e Gii generated CRUD) expects the request to be of post type, you can see this in the customer/delete action line:if(Yii::app()->request->isPostRequest){...}. So you have to send a POST request, again modify the ajax options:
CHtml::ajax(array(
...
'type'=>'POST',
'url'=>'',// copy from point 1 above
...
))
Alternatively you can also use CHtml::ajaxLink().
To update the CListView after deletion, call $.fn.yiiListView.update("id_of_the_listview");. Something like:
CHtml::ajax(array(
...
'type'=>'POST',
'url'=>'',// copy from point 1 above
'complete'=>'js:function(jqXHR, textStatus){$.fn.yiiListView.update("mylistview");}'
...
))