Button click, confirm at least row should be moved to user table using JQuery
I am using MVC3, EF Model first in my project.
I have a view with 4 tables, and then I have CustomPickedTable,
whenever the user clicks on a row inside those 4 tables that move to the row CustomPickedTable
, this is the code for it:
<script type="text/javascript">
$(function () {
$('.questionsForSubjectType tbody tr').click(function () {
var origin = $(this).closest('table').attr('id');
$(this)
.appendTo('#CustomPickedTable tbody')
.click({ origin: origin }, function (evt) {
$(this).appendTo('#' + evt.data.origin);
});
});
});
</script>
What I'm looking for is some kind of check that when the user clicks on the submit button there should be a rule that ensures that at least one row in each of these 4 tables should be wrapped to CustomPickedTable
, if it isn't shouldn't post the form but give the user an error.
This is one of my 4 tables, they are generated with a razor foreach loop in MVC
<div class="questionsForSubjectType" id="questionsForSubjectType_1">
<table class="box-style2" id="RandomID_c5b9bc7a-2a51-4fe5-bd3a-75b4b3934ade">
<thead>
<tr>
<th>
Kompetens
</th>
</tr>
</thead>
<tbody>
<tr>
<td data-question-id="16">Har konsulten Förmåga att lära sig nytt?</td>
</tr>
</tbody>
<tbody>
<tr>
<td data-question-id="17">Har konsulten rätt kompetens?</td>
</tr>
</tbody>
</table>
</div>
My custom table:
<table id="CustomPickedTable" class="box-style2">
<thead><tr><th>Choosen Questions</th></tr></thead>
<tbody>
</tbody>
</table>
Thanks in advance!
source to share
There might be a better way.
But I would add a data attribute or some kind of class to each of the TDs that you can move around and submitting a check for each value you require.
Created an example here: http://jsfiddle.net/y35Qf/1/
Basically I added an attribute called data-row and each table has its own value. On submit, I require each of these values to be in the CustomPickedTable - unless I am warning that something is missing - warn success again.
You can easily add so that you report what lines are missing or whatever validation you want.
Is this what you wanted?
source to share