Basically what i want is that in my view file i have a list of various restaurants,and in front of each of them is a "show" button,which on clicking should display three more buttons(dynamically),where each button performs some action regarding the corresponding restaurant name(like show menu,show reviews)(this action should be dynamic too). Can anybody help me with this implementation.
In the view you can place a link and a target container:
{{=A('the link', callback=URL('controller', 'function', args=[my_arg]), target="callback-target", _class="btn btn-default")}}
<div id="callback-target"></div>
If the link is clicked the function in controller is called and you can read the argument my_arg with:
def function():
data = request.args(0)
response.flash('Data received!')
return DIV('Return anything ...')
The returned data is displayed in <div id="callback-target"></div>
Related
I am using response from xml server. I am trying to display the different detail view when each BUtton is pressed respectively.When the Button is pressed, I want to send the Id of each button to the detailed page and I want to display that Id on the detailed page too.
My Button for clicking and passing ID to next view respective to each button clicked is:
<a href='{{route('Detailed',["Id" => $flight["Id"]])}}'>SELECT NOW</a>
$flight["Id"] is the response value that I get from the xml server
My route is for passing Id is: Id is what I want to pass from one view to another and display in second view
Route::get('/Detailed/{Id}',[
'as' => 'Detailed', 'uses'=>'FlightController#show'
]);
My controller function to display is:
public function show($Id)
{}
It gives me error saying that:
Missing required parameters for [Route: Detailed] [URI: Detailed/{Id}] in view.blade.php.
Please anyone help me
But if give direct value in button route
such as ID value then,
<a href='{{route('Detailed',["Id" => "1234"])}}'>SELECT NOW</a>
It works exactly what I expect.
Notes the Id value that I get is from simple_xml_response from server.
Try this:
Route
Route::get('detailed/{id}', 'FlightController#show')->name('detailed');
Controller
public function show($id) {}
Blade
<a href='{{route('detailed', '1234')}}'>SELECT NOW</a>
My main page renders a list of data coming from controller with foreach
#foreach ($sales as $sale)
<button id="{{$sale->id}}" #click="editClicked({{$sale}})">
#endforeach
I have an edit component placed on the page like this, I display it modally via showEditModal conditional
<edit v-if="showEditModal" #hide="showEditModal=false"></edit>
The component in brief is declared in Edit.vue:
<template name="edit">
...
</template>
This is simply a standard form with input fields, bound via v-model to the sale.
Essentially it is an update form, I intend to load the data from the main page into each input field to be edited.
My app.js simply sets showEditModal = true, in order to display the edit form on top of the main page.
Basically i don't want to have to call controller via GET method on loading the modal since i already have the data in the main page as $sale object, so im just wondering how do I pass in the $sale to the Edit.vue component ?
I thought that in the <edit> component usage, it would need to bind the sale object, however I'm unsure how that would work since it comes from the foreach loop.
I do, also have the data in the app.js method as passed in via #click="editClicked({{$sale}})", but again, i'm unsure how to use that to pass through ?
You're right, you would want to pass the current sale item as a property to the edit modal. What I would do is add a data property to your main Vue called selectedSale.
data:{
selectedSale: null
}
Then in your editClicked method, set selectedSale
methods:{
editClicked(sale){
this.selectedSale = sale
...
}
}
Finally, pass it as a property.
<edit :sale="selectedSale" v-if="showEditModal" #hide="showEditModal=false"></edit>
Is there any way to know that view is open by back?
For example
<div data-role="view" id="view-test" data-show="show">
<!-- View content -->
</div>
<script>
var show = function(e){
if(e.view.isBack())
{
console.log("Back")
// do something
}
}
</script>
Is there any method or property like e.view.isBack() ?
There are many ways to handle this, maybe you can use a global variable where you keep the last visited page or even you can add a back button handler and get the view from which the back button was pressed. Another solution would be to pass a parameter along with page navigation when going back, for example:
<a data-role="button" href="#foo?back=true">Link to FOO with back parameter set to true</a>
And on the visited page on show event you can get the parameter like this:
function fooShow(e) {
e.view.params // {back: "true"}
}
Now depending on what the parameter value is you can detect if the back button was pressed or not before reaching the page.
I have a view with a button and a DIV
I am trying to have this kind of functionality:
if the button is clicked - a controller method is executed ( i have the method, db.insert, etc.)
- if test (inside the controller method) is passed the button dissapears and the div appears ( I thought at using ajax - not to refresh the hole page)
whenever the page is refreshed the test has to be made again for the button to be visible or not
thanks
Something like this?
{{=DIV(A('click me',callback=URL('mycallback'),target="me"),_id="me")}}
def mycallback():
# do whatever you need to do
return DIV("I will appear in place of he link when you click")
I looked in more of your examples and I think my problem was simpler ( if there isn't any other solution)
So what I did was I used eval:
button in view :
<input id="b_normal" type="button" value="normal" onClick="ajax('{{=URL('db_test')}}',[],':eval')" />
and the controller method:
def db_test()
#tests and updates
return "jQuery('#b_normal').fadeOut();jQuery('#commDiv').show();"
for further refresh i used jquery, in view:
jQuery(document).ready(function(){
var flag = '{{=flag_normal}}';
if(flag == 'da')
jQuery('#b_normal').hide();
else jQuery('#commDiv').hide();
});
where *flag_normal* is sent by the main controller
I hope this is not too inefficient and if so, useful
When the following (PrimeFaces) button is pressed
<p:commandButton value="Search"
actionListener="#{personController.searchPersons}"
update="resultTable"/>
I load a list of objects and display them in a table on the current page. This is done via an Ajax call.
Now I'd like to do the following: If only one object is found, don't update the result table but link directly to the "detail page". (e.g. detail.xhtml)
How can this be done?
I know that i can control the navigation via the return value of my searchPersons() method. But It doesn't work as it should. I think it has to do with the update="resultTable" of my button. But I currently don't know how to solve this...
You can bring in some JS in oncomplete attribute. It will be executed when the bean action and the partial update is completed. You can change the window location in JS by assigning window.location a new URL.
Here's a random kickoff example, assuming that you've a persons table with id persons and that the detail link look something like <a class="detail" href="detail.xhtml?id=123"> somewhere in the table row.
oncomplete="var $persons = jQuery('#persons tbody tr'); if ($persons.length == 1) window.location = $persons.find('a.detail').attr('href');"