Repeated forms per table row using Angularjs - html

So...I have literally scoured the internet looking for a solution to this problem and haven't found any answer that directly (or indirectly) suggests an answer.
I am trying to create multiple forms within a table with each row being wrapped in <form> tags like so
<tr ng-repeat="item in items">
<form ng-submit="updateItem(item)">
<td ng-bind="$index + 1"></td>
<td ng-bind="item.title"></td>
<td><button>Submit</button></td>
</form>
</tr>
It seemed to work as intended until I realized that ng-repeat was not wrapping the <form> tag around the <td> tags and it ended up looking like so
<tr ng-repeat="item in items">
***<form ng-submit="updateItem(item)"></form>*** //The form tags were unwrapped
<td ng-bind="$index + 1"></td>
<td ng-bind="item.title"></td>
<td>
***<button>Submit</button>*** //Buttons don't submit cos no form
</td>
</tr>
whilst what I really want to achieve is something like
<tr>
<form>
<td>
<button>Hi</button>
</td>
</form>
</tr>
<tr>
<form>
<td>
<button>Hello</button>
</td>
</form>
</tr>
I would really love some help with how to deal with this.

You can unite cells:
<tr ng-repeat="item in items">
<td colspan="3">
<form ng-submit="updateItem(item)">
...
</form>
</td>
</tr>
Or use ngForm directive instead of form (and add submit on enter manually):
<tr ng-repeat="item in items" ng-form="myForm">
<td ng-bind="$index + 1"></td>
<td ng-bind="item.title"></td>
<td><button type="button" ng-click="updateItem(item)">Submit</button></td>
</tr>

You can add a new table in every row like this;
<table>
<tr ng-repeat="item in items">
<td>
<form ng-submit="updateItem(item)">
<table>
<tr>
<td ng-bind="$index + 1"></td>
<td ng-bind="item.title"></td>
<td><button>Submit</button></td>
</tr>
</table>
</form>
</td>
</tr>
</table>

Well, thanks to #pegatron and the Stack Overflow link he provided using #tjbp answer I ended up using the form attribute of input fields and that did it for me. Though its not been tested on all browsers, it does the trick of HTML5 validations. Here's what I ended up with.
<tr ng-repeat="item in items">
<form ng-submit="updateItem(item)" id="{{item.title}}">
<td ng-bind="$index + 1"></td>
<td ng-bind="item.title"></td>
<td><button form="{{item.title}}">Submit</button></td>
</form></tr>
And with this the form and its linked inputs gets sent with the button click.
Thanks.

Related

CSS: Table & TD with no border

Using angularjs with bootstrap 3 here.
I am trying to create dynamic rows when user clicks button. I have wrapped this inside a table and using ng-repeat.
When the second row is added it creates a separation b/w the two.
Below is my code:
<table class="table table-borderless">
<thead>
<tr>
<td>Text</td>
<td>Value</td>
</tr>
</thead>
<tbody ng-repeat="m in options">
<tr>
<td>{{m.Name}}</td>
<td>{{m.Country}}</td>
<td>
<a class="btn btn-xs" ng-click="Remove($index)"><i class="glyphicon glyphicon-trash"></i></a>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>
<input type="text" class="form-control" ng-model="Name" required />
</td>
<td>
<input type="text" class="form-control" ng-model="Country" required />
</td>
<td>
<a class="btn btn-xs" ng-click="Add()"><i class="glyphicon glyphicon-plus"></i></a>
</td>
</tr>
</tfoot>
</table>
I also created a demo at:
http://jsfiddle.net/Lyxbhosv/
Any inputs on how to remove the line or border in between two TD
I am not entirely sure what you're asking but via your example there is a double border whenever another row is added. To remove the double border and keep it a single just modify your code with the following:
<tbody ng-repeat="m in options" style="border: none;">
If you can explain further that would be great!
While I'm examining your code you have already awarded the answer. But here I'm coming up with what I have learned from your code and this answer:
<tbody ng-repeat="m in options" style="border: none;"> This will create lots of Repeatable `' in your code.
But if you placed your code 'ng-repeat="m in options"' to the child <tr>' tag it will repeat the ` each time. and it will not create any repeatable border any more.
<tbody>
<tr ng-repeat="m in options">
So the choice is yours!

A complicated dynamic table in HTML

I want to create a table where the same headings gets repeated in the same tr. It is a transcript in which semesters shall come side by side in the same row and it is fully dynamic, which means different marks according to semester will be shown as well as count of subjects may differ in each semester.
Could you please help me with this?
Here you can see the image of what the end result should look like
BTW, my approach was as follows:
<table class="table table-bordered center">
#foreach($exambatch as $exb)
<td>
<table class="table table-bordered">
<tr>
<td colspan="4" style="padding:5px;">
<b>Semester-{{ $semester->semester }}</b>
</td>
</tr>
<tr>
<td style="height:80px;">
<b class="vertical">
{{ Subject }}
</b>
</td>
<td>
<b class="vertical">
Something
</b>
</td>
<td>
<b class="vertical">
......
</b>
</td>
<td>
......
</td>
</tr>
<!-- Load Subjects -->
#foreach($sub as $subject)
<tr>
<td>{{ $sub->sub_name }}</td>
<td></td>
<td></td>
<td></td>
</tr>
#endforeach
But it doesn't work at all, I tried to use a table inside the td which worked however it didn't come in a singe row. Any good approach?

Taking HTML and changing to CSS to override plugin

I have the code for HTML and the developer of the plugin said to create a file which I have to change some of the wording the customer sees. I found the code in HTML (via firebug) and put it in the form but its not working so I am think I need to change more of it into CSS. This is what I have so far but again it didn't change anything.
I just want the wording to change instead of unlimited content just unlimited etc.
Thank you for any help.
<div class="fee-options-for-category">
<table class="fee-options">
<thead>
<tr>
</thead>
<tbody>
<tr class="fee-option fee-id-1">
<td class="fee-selection">
<input id="wpbdp-fees-radio-1" type="radio" data-canrecur="0" checked="checked" value="1" name="fees[91]">
</td>
<td class="fee-label">
<label for="wpbdp-fees-radio-1">Basic Listing</label>
</td>
<td class="fee-amount"> — </td>
<td class="fee-duration"> Unlimited </td>
<td class="fee-images"> 0 </td>
</tr>
<tr class="fee-description fee-id-1">
<td></td>
<td colspan="4">✓ put as much a you want.</td>
</tr>
<tr class="fee-option fee-id-2">
<td class="fee-selection">
<input id="wpbdp-fees-radio-2" type="radio" data-canrecur="1" value="2" name="fees[91]">
</td>
<td class="fee-label">
<label for="wpbdp-fees-radio-2">Featured Listing</label>
</td>
<td class="fee-amount"> $ 12.95 </td>
<td class="fee-duration"> 365 days </td>
<td class="fee-images"> 5 </td>
</tr>
<tr class="fee-description fee-id-2">
<td></td>
<td colspan="4">
✓ Unlimited content .
<br>
✓ Ratings support.
<br>
✓ Ability to attach files to your listing.
</td>
</tr>
</tbody>
</table>
</div>
thank you in advance
Susan

HTML Table Manipulation(multiple rows/cols in one <tr> or <td>)

I am making a form for inserting recipes to my database, whenever im dealing with forms, i always go for simplicity -> tables.
For example i have this code:
<table>
<tr>
<td>
<tr>Text:</tr>
<tr>
<input type="button" />
</tr>
</td>
<td>
<input type="text" />
</td>
</tr>
</table>
I wanted to have 2 rows inside a column, The above code doesnt actually work, im just demonstrating on how i would like it to arrange.
Is there anyway to do this? or do i have to resort to using divs and CSS(ugghh,, i hate this part. trial and error on the location.....)
<table>
<tr>
<td>
<table>
<tr>
<td>Text:</td>
</tr>
<tr>
<td><input type="button" /></td>
</tr>
</table>
</td>
<td>
<input type="text" />
</td>
</tr>

Column width in HTML table

How I can cause the second <td> (which contain <input>) attribute to occupy 3/4 of the table width?
<table>
<tr>
<td>
Name
</td>
<td>
<input type="text"/>
</td>
</tr>
</table>
I tried setting to td colspan=3, but it doesn't help me.
<table>
<tr>
<td style="width: 25%">
Name
</td>
<td style="width: 75%">
<input type="text"/>
</td>
</tr>
</table>
Just a quick and dirty solution. Would be better to style these kinds of stuff in a seperate css file and use classes instead of inline css.
A better way would be to use colgroups to style and describe the columns of the table. you can read about that here: http://www.w3schools.com/tags/tag_colgroup.asp
You can set the width:
<table>
<tr>
<td width="25%">
Name
</td>
<td width="75%">
<input type="text"/>
</td>
</tr>
</table>
(or use css with those percentages instead, i.e. style="width: 25%" or class="yourCssClassThatHasTheWidthPercentageSetInIt")
Colspan is for when you want a cell to span multiple columns in other rows.
But is there any reason you are using tables instead of divs for layout?
The correct (assuming this was legitimately tabular data) way would be to add a <colgroup> as razhial has already suggested which might look like this (demo with some extra CSS to see how it's working):
<table>
<colgroup>
<col/>
<col width='75%'/>
</colgroup>
<tbody>
<td>Name</td>
<td><input type="text"/></td>
</tbody>
</table>
However from your example there appears to be a much cleaner approach that is the <label> element that works like this (demo):
<label for="Name">Name</label>
<input type="text" id="Name"/>