Cake php js helper, using jquery append - ajax

<?php
echo $this->Js->submit('Submit',array(
'before' => $this->Js->get('#beforesend')->effect('fadeIn', array('buffer' => false)),
'complete' => $this->Js->get('#beforesend')->effect('fadeOut', array('buffer' => false)),
'update' => '#contentc'
));?>
i was able to create an ajax call with the above code.
but what i want is to create multiple ajax request and append the output to previous ajax output.
my code overwrites the div simply because i have given an "update"
is there any way by which i can use jquery append.

You might be better off setting update to a hidden div, and then copy or move the contents of that hidden div to append to #contentc as a part of the complete action.

Generating javascript by passing php array is good in the case of simple function, but this is kind of difficult when you try for complex one,
So what i did was simply create a page with the javascript functions and add it in the $content_for_script variable.

Related

Ajax call and then include a blade section

I have a {{!! Form::model!!}} where I am passing a variable $values from the Controller and displaying it inside of the Form select those values. In mine main blade i have 3 additional blades I am including through
#if($jobs->open)
#include('jobs.review.open')
#endif
I am trying to load the data $jobs from controller only when someone clicks , I figured to do some by create an ajax call with onclick event, so i have the data $jobs back. An only now trying to include jobs.review.open blade.
Any help will be appreciated
One common strategy is to put the rendering in the AJAX call. The server returns a ready-to-go chunk of HTML in its reply, and the JavaScript code simply inserts it into the DOM at the appropriate place with innerHTML. The server uses a blade to prepare the HTML that it then returns.
The initial page HTML that is displayed doesn't include the content, but does include dummy placeholder <div>s which mark the places where the HTML will be inserted.

Laravel - Get HTML of current page or of a view according to a path

I have a view mypage.blade.php and a route.
The url is like : https://example.com/mypage/param1/param2. The route use param1 and param2 and generate the page.
Question 1
In that page, I try to get its HTML code. Is there a way to do it?. I tried render() but I don't get what I want.
Question 2
In the view, can I get the HTML code of an other view by specifying a path ?
You had the right idea. Not sure why it wouldn't work for you.
In the controller, set the view into a variable:
$view = view('myBaseView', compact('people', 'places', 'things'));
Now, if you dump the rendered view variable, you have the page's HTML:
dd($view->render());
To get the html of another view by specifying the path and using the internal controller, you would need to set up some kind of a wrapper or catch so that the view variable is not returned as a view, but rendered out to html as above. Your method would need to trap whatever the original controller was sending before it pushed out the view.
Of course, old school php can get the other page's rendered html too possibly if your server is set to allow this:
$html = file_get_contents('http://mypage.com/');
Something else you might find handy is the Laravel sections method. If you just want to render part of the page you can do so by calling whatever section you want from a partial view:
$sections = $view->renderSections(); // returns an associative array of 'content', 'pageHeading' etc
dd($sections['modalContent']); // this will only dump whats in the content section
I don't know what you want to do with this html, but if you wish to display it on a page, once you send it (you'd possibly want to return the view along with a compact of the variable $view... as a normal variable if so), remember to use this format:
{!! $view !!}
HTH

Passing form button data

I wondered, how to pass some kind of data from form button (id, or anything else) to use it in if statement, to regulate what form elements are showing.
Can i pass ID some how, can't seem to find documentation about this, and i dont want to use javaScript so much.
{{Form::button('Change form data', ['id'=>"izvele",'class' => 'btn btn-success'])}}
#if(?????????????)
#endif
You can use code like this,
if (request()->has('izvele')) {
...
}
but only after submitting the form.

Missing elements in Product-list.tpl when use BlockLayered module (AJAX refresh)

Im facing a problem with BlockLayered module. Product-list.tpl loses their elements (table with data obtained from array) when AJAX call (BlockLayered filter) refresh the page...
Im not sure where to find solution. There also missing Dodaj do schowka button (favoriteproducts module)
Module blocklayered in ajaxCall() method uses its own data to pass into product-list.tpl template, so if you e.g. overrided some core methods to pass additional data in template (as I see you did), blocklayered know nothing about it and will ignore it during ajax page updates.
To fix it put you changes in ajaxCall() method too. Do not forget, from version 1.6.1.1 Prestashop allow use modules override, so you can leave original blocklayered.php unchanged, for further updates.
upd explanations with code:
in ajaxCall method you need to have something like
$smarty->assign(
array(
'myQuantity' => 10,
'homeSize' => ...,
'nb_products' => $nb_products,
...
));
then in product-list.tpl
{if isset($myQantity)}
{$myQantity}
{/if}
it works.

Yii - Ajax Form with validations

I am a Yii Newbie, and I have the following problem.
I have a form that is going to be like an admin - backend form. It will have loads of buttons each having their own "action" in the controller class. Now all I want to do is to validate the form elements, depending upon a "scenario" and to display appropriate error messages if all the parameters needed for the action is not filled in properly.
Can some one show me how I can do this without me having to reload the page?
[ I have found out a way, but I dont know if what I am doing is "technically" correct. I have submit buttons for all the actions that I want to perform in the form, and in the respective actions, I perform the validations and renderPartial form data back. OnSuccess of each button replaces the data of the entire "form-div" by the data that was retured from the controller. It works, but I want to know if this is the only way to achieve this.]
you should enable CActiveFom ajaxformvalidation property to true see the following example
in your controller action
you should uncomment the following lines
$this->performAjaxValidation($model);
in your view
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'test-form',
'enableAjaxValidation' => true,
));
?>

Resources