ng-repeat shows diffent values during execution - javascript

[Problem]
Ok, I have no idea of what is really going on here. But here is the thing: I'm showing a table with some information from users and there's a button that the user can click in order to show more information from that user. The approach I took to create this is for each user a form is created to send the information when the users hits the button "Check".
Everything sounds fine, but, there are random moments when I access the system the field 'ID' from the table (<td>{{data.id}}</td>) shows the value of the id correctly but the (<input type="hidden" name="_user" value="{{data.id}}" />) doesn't. They come from the same object, data.id, how come they could show different values?
The code for the table follows:
<tr ng-repeat="data in filtered = (list | filter:search | orderBy : predicate :reverse) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">
<td>{{data.id}}</td>
<td>{{data.name}}</td>
<td>{{data.city}}</td>
<td>{{data.state}}</td>
<td>{{data.country}}</td>
<td>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="submit" name="check" value="Check" />
<input type="hidden" name="_user" value="{{data.id}}" />
</form>
</td>
</tr>
If somebody helps me on this I'd really appreciate. I also would appreciate any comment related to the approach I've taken in order to send the data to the server. Thanks in advance.
[How to reproduce]
When I access the screen for showing the users from the main panel, the table above shows everything rendered fine and the hidden values are set correctly. Then if I click on "check", I'll see the user data in another screen and if I hit the back button from the browser, I'm able to see the table above rendered properly (the id field in the table is correct) but the hidden field get the value="0". All of them.
[Solution]
Using ng-value instead of value saved me! Thanks you all!

Use the following resource of angularJs, ngValue.

Related

Use Product Variants Select in Cart Prestashop

I'm developing a cross sell module that will display products in cart that you can add to cart by clicking the button add to cart.
I need to take consideration of product variants (attributes).
I've already find out how to add the add to cart button to the cart page thanks to this code :
<form action="{$urls.pages.cart}" method="post" id="add-to-cart-or-refresh">
<input type="hidden" name="token" value="{$static_token}">
<input type="hidden" name="id_product" value="{$product->id}" id="product_page_product_id">
<span class="remove-from-cart">
<button class="btn btn-primary add-to-cart" data-button-action="add-to-cart" type="submit"
{if (!$product->checkQty(1))} disabled {/if}>
<i class="material-icons float-xs-left">shopping_cart</i>
{l s="Add to cart" d='Shop.Theme.Actions'}
</button>
</span>
</form>
But what I need now is to update the display price depending about the value chosen with the select option value dropdown set as on my product page and use the attribute id selected in order than when the user click on the add to cart button, it add to cart the product with the good attribute and not the default one
I'm sure that is from js script that the price is updated but I don't really find out which function is in charge of this
This is the select option as asked
<div class="clearfix product-variants-item">
<span class="control-label">ATTRIBUTE_GROUP_NAME</span>
<select class="form-control form-control-select" id="group_ATTRIBUTE_GROUP_ID" data-product-attribute="ATTRIBUTE_GROUP_ID" name="group[ATTRIBUTE_GROUP_ID]">
<option value="ATTRIBUTE_ID" title="ATTRIBUTE_NAME" selected="selected">ATTRIBUTE_NAME</option>
</select>
</div>
the solution is not very simple but is achievable, the same way as prestashop works on product page, you have to ajax refresh your content on the attribute change. We developed a complex upselling module on checkout using the same method and it works good.
The logical steps are:
-> Select value is changed
-> submit the data via ajax
-> get the fresh and updated data, best choice for me is to render your module view again and get an html as response
-> replace your content with the new html
Another way, not tested because little bit more complex in my opinion, could be to store in javascript all the data about all the variations/combinations and handle the logic there to get the price data you need on every change. A problem with this solution is that the data could be not always updated because stored locally.
I hope my hint helps, I wanted to comment but my ranking is still too low and I have to reply instead.
Simone

Laravel: get last insert id and show it before registration

I need to display the last value of id,in an input form when I open the page of regestration ( befor to add a new user). help me
<input type="text" id="text" value="{{$last_id}}" >
but I don't have any idea about where I have to set this ligne:
$last_id =DB::table('clients')->max('id');
If the purpose of this is to have the right incremented value when you create the client, the database can handle it for you if you wrote your migration the right way. If it's the case, just paste your migration for the clients table and I'll show you the way to do it.
If you just want to display it, you can write it that way, but make sure this is the right way to do what you want to do here :
<input type="text" id="text" value="{{ DB::table('clients')->max('id') }}" >
Let me know if it helped you

HTML populate select menu from input without submitting data?

I have created an input form in HTML with a combination of input and select boxes. I would like to populate a select menu on the fly with data from the input boxes - for example:
Employee One: Jim
Employee Two: John
Employee Three: Bob
This would then populate a select menu with the Jim, John and Bob as options.
I am trying to avoid having to submit the input data first as I would really like to have all the input on one page. I submit all the data to a MySQL database, so worst case I could submit it in sections and read it back, but would appreciate any suggestions for doing it on the fly.
Thanks for any help.
Blair
Maybe something like this?
HTML:
<input id="employee_name" type="text" placeholder="Type here the Employee name"/>
<input id="add_employee" type="button" value="add"/>
<select id="employee_list">
</select>
Jquery:
$('#add_employee').click(addEmployee);
function addEmployee(){
var employee_name = $('#employee_name').val();
$('#employee_list').append('<option value='+employee_name+'>'+employee_name+'</option>');
}

Creating a Query String HTML form that passes through pages?

I am very new to dev and probably biting off more than I chew right now. :0
I am looking to create a query string form that will stick through a users session, no matter what backpages they travel between during the visit.
This is what i got so far, its not much, but It does accomplish some of what I'm trying to do.
<div style="text-align: center;">
<form method="get" action="http://www.example.com">
<input name="n" value="Show" type="hidden">
<input name="id"> <input type="submit">
</form> </div>
This code builds the form and send the user to the custom submitted query link after entry, however, I would like the custom query to stick all pages they visit. In this code the query is only valid for the initial page after entry.
Need the query stay attached to child pages thereafter as well: IE: http://example.com/blob/?id=44553355 as well as http://example.com/blog/article/?id=44553355
Any suggestions on how to tweak the form or accomplish this task I would very much appreciate it.
Thank you.
start a session and store what you need in it
session_start();
$_SESSION['query']='Query goes here';
When the user hits a point where you no longer want them to have the link remove the variable from the session and end it.
unset($_SESSION['link']);
session_destroy();

Dynamically displaying the column names

I have a requirement where I have to display questions dynamically based on the buttons clicked. I have coded a table where in one column I display the question and another column I want the user to enter answer. Now when I save this form data I actually need to save the question id and not the question. So I thought I can display the question in the name area like <td> question 1 </td> and in the value field I can keep the question id.
<td>
<input type="text" id="q1" path="genericq1" value=""> dynamic question name
</td>
I am getting the questions by making an ajax call
$('#q1').val(data.question[key1].question);
Can anyone please hint me a way by which I can dynamically display question in the column and keep the question value in the value field which goes in the back end?
Have you heard about hidden field? Use hidden field to store your id. And for displaying name use label instead.
Like in your code
<td>
<input type="hidden" name="qid" id="qid"/>
<label id="qname"></label>
</td>
And when you getting data from ajax call write it as below
$("#qid").val(data.question[key1].questionid);
$("#qname").text(data.question[key1].questionname);
You can easily associate data with an element in jQuery
$('#q1').data('qid',data.question[key1].questionid);
Which can then be retrieved using
$('#q1').data('qid');

Categories