Change blade template variable - ajax

I've read many articles about how to pass variables and assigning variables in a blade template, but my question is:
How to change a variable value based on ajax response? Is it possible?

You can make a hidden input in your template which first is initialized from controller:
<input class="input" id="inputHidden"
name="inputHidden"
value="{{$variableName}}" hidden>
where $variableName is the variable sent by te controller along with the view.
after that change the value returned on ajax success branch to this hidden input like that:
$('#inputHidden').attr('value',returnedValueByAjax)

Related

How to hide parameter from url, when need to pass data from one page to another?

Instead of showing ../product/1
$breadcrumbs->push($name,url('/product/'.$id));
I want it to be displayed as ../product
Any method can be used to do this ?
Use hidden input field like:
<input name="id" value="{{$id}}" hidden>
Not a too good practice, But you can hide id parameter from url

Is there a way to pass selected drop-down value to other controller in angular js?

i have a drop-down in the main controller. And i want to pass the selected value to another directive which builds charts.
In main.html i have:
<select class="form-control" ng-options="s as s.Name for s in Data"
ng-model="SelectedDataoption" ng-change="DataSelected()" ></select>
<build-chart selected={{selectedvalue}}></build-chart>
in main.js
$scope.DataSelected=function(){
$scope.selectedvalue=$scope.SelectedDataoption.Name};
but i get empty value in build-chart controller.
You can try to put the value in $rootScope (in common with all the controllers by definition). But I'm not sure it is the best solution.

AngularJS : ng-model in ng-repeat

I m beginer in AngularJS, and i try to do this :
<form ng-repeat="prop in tab">
<input ng-model="prop" type="text">
</form>
{{tab}}
With this code inputs values is ok, but when i edit value the reverse binding to "tab" don't work.
How i can simply do this ?
Thanks for yours tips ;)
If you want to see changes in your html document live you either need to move the expression inside the form tag and change it to {{tab.prop}} or outside the tag but also showing the property you are interested in displaying such as {{tab.somePropertyName}}.

Grails - Passing domain parameter to Javascript

Is there a way to pass an instance variable in my gsp file to Javascript?
This is what I have that doesn't work:
<input type="button" value="Add" onclick="addTo('${person.id}');" />
${person.id} is the ID of the domain instance Person.
That works just fine for me. I'm able to send an id to a javascript function and show it in an alert. Are you getting an error, or is the value just not being passed? Maybe add your javascript to the question.

How to recognaize which ajax form it is in Django?

I have view which takes care of all the Ajax submits from the client side. And to differentiate them by I uses different submit button names such as this one
<input type="submit" value="Send" name="send_message">
Suggested from this question.
The only problem is that from the view side it doesn't seems to carry the name to the server side so I cannot use the following if-statement
if 'send_message' in request.POST:
It works if I send it normally with page fresh. But I want to use it with Ajax.
I came up with a hack that you can add this name with jQuery. Simply by after serializing() your data you then concatenate the name attribute by data += "&send_message"
Then the if statement will work. But it doesn't seems so clean. So I wonder if there's a better way to handle this? Or should I make different views to handle the different Ajax calls I have?
You really should post each form to a different URL.
If not, you could add a hidden input with the name of the form as the value.
<input name="form_name" type="hidden" value="form_1" />
views.py:
form_name = request.POST['form_name']

Resources