Improve page performance by reducing number of binding with AngularJS? - performance

Context
I'm building a list a results where each result can be edited by users.
Approach
Currently I'm repeating the visible <span> tag that displays a result as well as the hidden <input> tag used to edit this same result. See the last <td> :
<tr ng-repeat="entry in paginateDict | orderBy:predicate:reverse" class="form-inline" role="form">
<!-- Edit buttons -->
<td>
<div class="radio">
<label ng-hide="editMode" title="edit">
<input class="sr-only" type="radio" name="edit"
data-ng-click="editMode=true">
<span tooltip="edit" class="fa fa-pencil fa-lg"></span>
</label>
<label ng-show="editMode" title="save">
<input class="sr-only" type="radio" name="edit"
ng-model="editMode" ng-click="submitEntry(true)">
<span tooltip="save" class="fa fa-save fa-lg text-primary"></span>
</label>
<label ng-show="editMode" title="cancel">
<input class="sr-only" type="radio" name="edit"
ng-model="editMode" ng-click="submitEntry(false)">
<span tooltip="undo" class="fa fa-times fa-lg text-danger"></span>
</label>
</div>
</td>
<!-- Content -->
<td ng-show="pyn" lang="cmn-py" data-id="{{entry.cid}}">
<span ng-hide="editMode">{{entry.pyn | pinyin }}</span>
<input type="text" placeholder="{{entry.pyn}}" ng-model="entry.pyn" ng-show="editMode" class="form-control">
</td>
</tr>
Each line as 5 editable columns and each column as two binding (on <span> and <input>).
Question
In order to improve page performance, by reducing the number of binding, is there an Angular way to dynamically create and attach the <input> to a row when the edit radio button is click ?

You can do that using ngIf directive instead of ng-show
The ngIf directive removes or recreates a portion of the DOM tree based on an {expression}.
<td ng-show="pyn" lang="cmn-py" data-id="{{entry.cid}}">
<span ng-hide="editMode">{{entry.pyn | pinyin }}</span>
<input type="text" placeholder="{{entry.pyn}}" ng-model="entry.pyn" ng-if="editMode" class="form-control">
</td>

Related

Button can't save first item when clicked

In a foreach loop, I have more than one item and each item has a button called "save". However, when I click on the first "save" button, it saves only the last item in my database.
#foreach($product_dr as $product)
<tr>
<td style="font-size: 20px;color: #101010">
<div class="form-group">
<input type="hidden" name="title" value="{{$product->title}}">
<label for="inputText3" class="col-form-label"></label>
{{$product->title}}
</div>
</td>
<td style="font-size: 20px;color: #2ec551">
<div class="form-group">
<input id="inputText4" VALUE="{{$product->price}}" type="text" name="price" class="form-control" placeholder="Amount" style="width: 100px">
</div>
</td>
<td style="font-size: 20px;color: #2ec551">
<div class="form-group">
<input id="inputText4" VALUE="1" type="number" name="amount" class="form-control" placeholder="Amount" style="width: 100px">
</div>
</td>
<td style="font-size: 20px;color: #2ec551">
<div class="form-group">
<input type="hidden" name="table" value="{{$table[0]->number}}">
<input type="hidden" name="table_number" value="{{$table[0]->number}}">
<label for="inputText3" class="col-form-label"></label>
{{$table[0]->number}}
</div>
</td>
<td>
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12 ">
<button class="btn btn-success" type="submit">Save</button>
</div>
</td>
</tr>
#endforeach
The name of the variables must be an array as such:
<input type="hidden" name="title[]" value="{{$product->title}}">
This way you will have an array on your backed that you can iterate. If not, you will only get one value for "title"

XPATH, return specific elements within specific div

From this particular div below, I am trying to grab the available sizes, which is the "value" property here:
<input id="swatch-0-s-6072559239" type="radio" name="option-0" value="S" class="">
So I need to return: XS, S, M, L, XL
I have been trying variations of this:
//div[#class='swatch_options']following-sibling::input#value
But this is not working.
<div class="swatch clearfix" data-option-index="0"> <div class="option_title">Size</div> <input id="swatch-0-xs-6072559239" type="radio" name="option-0" value="XS" checked="" class=""> <div data-value="XS" class="swatch-element xs-swatch"> <label for="swatch-0-xs-6072559239">
XS <span class="crossed-out"></span></label></div> <input id="swatch-0-s-6072559239" type="radio" name="option-0" value="S" class=""> <div data-value="S" class="swatch-element s-swatch available"> <label for="swatch-0-s-6072559239">
S <span class="crossed-out"></span></label></div> <input id="swatch-0-m-6072559239" type="radio" name="option-0" value="M" class=""> <div data-value="M" class="swatch-element m-swatch available"> <label for="swatch-0-m-6072559239">
M <span class="crossed-out"></span></label></div> <input id="swatch-0-l-6072559239" type="radio" name="option-0" value="L" class=""> <div data-value="L" class="swatch-element l-swatch available"> <label for="swatch-0-l-6072559239">
L <span class="crossed-out"></span></label></div> <input id="swatch-0-xl-6072559239" type="radio" name="option-0" value="XL" class=""> <div data-value="XL" class="swatch-element xl-swatch available"> <label for="swatch-0-xl-6072559239">
XL <span class="crossed-out"></span></label></div>
Your xpath syntax for following sibling and input#value are wrong,
try below
//div[#class='swatch clearfix']/input[#name='option-0']
Also, your parent div tag is not closed.
Check the output here
https://codepen.io/ajanth2012/pen/MXaPpp?editors=1010

Laravel - Creating a website to imitate estimatemyapp.com, can't get input from radio buttons and checkboxes?

I'm currently stuck on how to get input from radio buttons and check box and calculate their value? enter image description here
<h1>5.{{$result}} Dates & Locations</h1>
#foreach ($dates as $product)
<li>
<input type="radio" name="get" id="{{$product->id}}"
value="{{$product->price}}" />
<label for="{{$product->id}}">
<img src="{{URL::asset($product->image)}}">
</label>
</li>
#endforeach
<h1>6. Social & Engagement</h1>
#foreach ($social as $product)
<li>
<input type="checkbox" name="5"
id="{{$product->id}}" value="{{$product->price}}" />
<label for="{{$product->id}}">
<img style="border-radius:50%;"
src="{{URL::asset($product->image)}}">
</label>
</li>
#endforeach
<span id="price" data-format="$ 0,0[.]00"
data-formula="($1+$2+$3+$7+$8+$9+$10+$11+$12+$13+$14+$15+$16+$17+$18+$19+$20+$21+$22+$23+$24)+(($4+$5+$6)/100*($1+$2+$3+$7+$8+$9+$10+$11+$12+$13+$14+$15+$16+$17+$18+$19+$20+$21+$22+$23+$24)) " readonly="readonly" class="readonly">$ 0
</span>
</form>
</div>

Kendo UI stripping bootstrap styles

Using Bootstrap 3 the following code is used for a Radio Group. This displays as a set of buttons that when checked set the button to the active state. (append the class .active)
HTML
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" name="options" id="option1">Option 1
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="option2">Option 2
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="option3">Option 3
</label>
Normal function in "checked" is the appended active class
<label class="btn btn-primary active">
<input type="radio" name="options" id="option1">Option 1
</label>
When Kendo.all.web.js is used - all classes EXCEPT the active are stripped. Making the button change into a checkbox
<label class="active">
<input type="radio" name="options" id="option1">Option 1
</label>
How can this be corrected? I can't see anywhere where the code is coming from that is doing this.

Bootstrap Radio buttons not working properly in firefox

I have recently started using bootstrap to create a front end to a website. I was using chrome to develop it originally. I recently started testing on firefox and I ran into a problem. I have a few radio buttons on the front page. When I click on the one I want it looks as if it is only selecting the first one and not the one I am clicking on. If I click quickly a few times it makes the selection properly. Any ideas why this is happening? The code is here :
<form action="redirector.php" action="get">
<fieldset>
<table border="1">
<tr>
<td valign="top"><b>Please select a genome:</b><br>
<label class="radio">
<input type="radio" name ="genome" value="Acral2">Acremonium Alcalophilum<br><input type="radio" name ="genome" value="Aspni3">Aspergillus niger<br><input type="radio" name ="genome" value="Glotr1_1">Gloeophyllum trabeum<br><input type="radio" name ="genome" value="Phchr1">Phanerochaete chrysosporium<br><input type="radio" name ="genome" value="PleosPC15_2">Pleurotus ostreatus<br><input type="radio" name ="genome" value="Spoth2">Sporotrichum Thermophile<br><input type="radio" name ="genome" value="Thite2">Thielavia terrestris<br> </label>
</td>
<td valign="top">
<b>View proteins with JGI annotation of type:</b><br>
<label class="radio">
<input type="radio" name ="jgiAnnotation" value=sigPInformationView>SignalP Information<br>
<input type="radio" name ="jgiAnnotation" value=ecInformationView>EC and Pathway Information<br>
<input type="radio" name ="jgiAnnotation" value=domainInformationView>Domain Information<br>
<input type="radio" name ="jgiAnnotation" value=goInformationView>Go Information<br>
</label>
<button type="submit" class="btn">Submit</button>
</fieldset>
</form>
</td>
<td valign="top">
<form action="annotationInfoView.php" action="get">
<fieldset>
<b>View single protein:</b><br>
Enter our ID number:<input type="text" name ="ourId"><br>
(i.e. jgi_Spoth2_2293939)<br>
<button type="submit" class="btn">Submit</button>
</fieldset>
</form>
</td>
</tr>
</table>
http://jsfiddle.net/CTF2s/
The problem is you have multiple radio buttons inside of a single label.
If I click quickly a few times it makes the selection properly.
This is probably because you're clicking directly on the radio button and not the text next to the radio button. This is how all browsers will behave, including Chrome.
Check out the "Checkboxes and radios" section of Twitter Bootstrap's "Forms" documentation for a working example.

Resources