How do I implement something like this? - asp.net-mvc-4

Well I have to implement something as follows:
I need to display a list of Contact IDs of all the contacts I have in my model.
<ul>
#for (int i = 0; i < Model.Contacts.ToList().Count; i++)
{
<li><a onclick="showContactInfoDialog(#Model.Contacts.ToList()[i].ContactId)">Model.Contacts.ToList()[i].ContactId</a></li>
}
</ul>
Each list element will be clickable, upon clicking which, a dialog will popup.
function showContactInfoDialog(id) {
document.getElementById('contact-dialog').style.display = 'block';
}
The dialog should show that particular contact's First Name, Last Name, Title, Email.
<div id="contact-dialog">
<form action="Contact/SaveContactEdits" method="post">
<table>
<tr>
<td>First Name</td>
<td>
<input type="text" name="FName"value="#Model.Contacts.ToList()[id].FirstName" /></td>
</tr>
<tr>
<td>Last Name</td>
<td>
<input type="text" name="LName" value="#Model.Contacts.ToList()[id].LastName" /></td>
</tr>
<tr>
<td>Title</td>
<td>
<input type="text" name="Title" value="#Model.Contacts.ToList()[id].Title" /></td>
</tr>
<tr>
<td>Email Address</td>
<td>
<input type="text" name="Email" value="#Model.Contacts.ToList()[id].Email" /></td>
</tr>
</table>
<input type="submit" value="Save"/>
</form>
</div>
The dialog should let user make edits to the contact's details.
How do I do this? I'm having problem in passing the 'id' parameter to the dialog box element.
<div id="contact-dialog">

I'm having problem in passing the 'id' parameter to the dialog box
element.
The way you are using the id is not correct as you use it like the following. In the given code below (taken from your code) you are using the id as the index and that won't work most of the time especially if the ids does not start with 0.
Model.Contacts.ToList()[id]
That also won't work because the onclick event happens on the client side where the model is no longer available. So what you can do, since calling another controller method is not an option is to write all the details in a hidden field. Put them on a single container, for example one div per contact, the assign the id of the contact to the div. When the a tag is clicked, you read the values from the div and assign them to the form. All of this can be handled easier with tools like knockout, but if using it is not an option then here's the code that will do the trick.
// in your loop do this
// btw, it would be better if you Contacts object is an IList so you can do indexing easier
<li><a onclick="showContactInfoDialog(#Model.Contacts.ToList()[i].ContactId)">Model.Contacts.ToList()[i].ContactId</a>
<div id="#("contactrow"+Model.Contacts.ToList()[i].ContactId)">
#Html.HiddenFor(m=>Model.Contacts.ToList()[i].FirstName)
// do the same for the rest of the fields you want to show on the dialog
</div>
</li>
before you show the dialog, copy the contents to the form:
function showContactInfoDialog(id) {
// we are targetting this -> <input type="text" name="FName"
// assign an id (fname) for optimal performance
var container = $("#contactrow"+id);
        $("#fname").val(container.find('#FirstName').val());
// do the same for the rest of the fields
document.getElementById('contact-dialog')
.style.display = 'block';
}

Related

How to post table cell value in a Razor page

Looking for ideas on how to pass the 'RecordId' value for the specific row in the table, when the 'view details' button for that row is pushed. This project is .NET Core 5 Web app with Razor pages. I'm not set on the button, open to other ideas to post the value and display the details.
Here is snippet of code generating the table rows:
#foreach(var x in Model.masterrecords)
{
<tr class="border text-center">
<td>#x.RecordId</td>
<td>#x.FirstName</td>
<td>#x.LastName</td>
<td>#x.NumberOfRecords</td>
<td>
<input type="submit" asp-page-handler="ViewDetailsBtn" value="view details" class="btn btn-sm" />
</td>
</tr>
}
Try to use a form to post RecordId:
#foreach (var x in Model.masterrecords)
{
<tr class="border text-center">
<td>#x.RecordId</td>
<td>#x.FirstName</td>
<td>#x.LastName</td>
<td>#x.NumberOfRecords</td>
<td>
<form method="post" asp-page-handler="ViewDetailsBtn" asp-route-RecordId=#x.RecordId>
<input type="submit" value="view details" class="btn btn-sm" />
</form>
</td>
</tr>
}
handler(If your RecordId is string type,try to use string RecordId):
public void OnPostViewDetailsBtn(int RecordId)
{
}
result:

Cannot validate dynamic input fields in vue.js using vee-validate

I am generating some inputs fields on my vue component page dynamically like given in below code:
Script part:
data(){
return {
forminputs: [
{
fairPaid: '',
}
],
}
Component:
<tr v-for="(input,k) in forminputs" :key="k">
<td>
<input v-validate="'required'" name="fairPaid" type="text" :class="['form-control', {'is-invalid': errors.has('fairPaid')}]" v-model="input.fairPaid">
<div v-show="errors.has('fairPaid')" class="invalid-feedback">
{{ errors.first('fairPaid') }}
</div>
</td>
</tr>
The fields are being validated but there is one issue if the error is on one input field but the error message gets displayed in all input fields. The error message should be there on the field where the error occurs and i don't want to change the field name. Any suggestions will be highly appreciated
The errors are associated by the input's name attribute, so those should be unique. Instead of just 'fairPaid', bind 'fairPaid' + k (with the v-for's k index as a suffix) to name, and use that as a key in the errors bag:
<tr v-for="(input,k) in forminputs" :key="k">
<td>
<input v-validate="'required'" :name="`fairPaid${k}`" type="text" :class="['form-control', {'is-invalid': errors.has(`fairPaid${k}`)}]" v-model="input.fairPaid">
<div v-show="errors.has(`fairPaid${k}`)" class="invalid-feedback">
{{ errors.first(`fairPaid${k}`) }}
</div>
</td>
</tr>

How to associate one input to another(change one also change another)

I am using vue 2.x via <script>.
I have a page contains a list of users, they are shown in a table and users can edit it:
name description1 description2
1st name input 1st description1 input 1st description2 input
2nd name input 2nd description1 input 2nd description2 input
....
For description1 and description2, they may contain a long content, but the input only show one line(I cannot use textarea here).
Therefore, I need to do:
If user click description1 input, there is a big popup dialog shown such that user can see the complete content and edit it in popup, after editing, if user click save button of popup, then the new content will be transferred to description1 input which user click;
If user click description2 input, there is a big popup dialog shown such that user can see the complete content and edit it in popup, after editing, if user click save button of popup, then the new content will be transferred to description2 input which user click;
and so on.
I have a main.jsp which includes student.html and the student.html as follows:
<div id="studentDiv">
<table>
<thead>
<tr>
<th>Name</th>
<th>Description1</th>
<th>Description2</th>
</tr>
</thead>
<tbody>
<tr v-for="s in studentList" :key="index">
<td><input v-model="s.name" /></td>
<td><input v-model="s.description1" /></td>
<td><input v-model="s.description2" /></td>
</tr>
</tbody>
</table>
<div class="modal fade" id="popupDialog" role="dialog"
aria-labelledby="modalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl modal-dialog- scrollable" role="document">
<div class="modal-body">
<textarea v-model="popupTextArea"></textarea>
</div>
</div>
</div>
<script>
studentVM = new Vue({
name:'student',
el: '#studentDiv',
data() {
return {
studentList:[],
popupTextArea: ''
}
},
......
})
</script>
</div>
popupDialog div is the popup dialog(bootstrap modal).
So how can I achieve my goal in Vue? How can I sync popup dialog value and input value of list student?
You can save the selected student + the property of the student you want to change, and apply the change when you click the save button:
data() {
return {
studentList:[],
popupTextArea: ''
selectedStudent: null,
selectedStudentProperty: '',
}
},
methods: {
selectStudent(student, property) {
this.selectedStudent = student;
this.selectedStudentProperty= property;
}
onPopupSave() {
this.selectedStudent[this.selectedStudentProperty] = this.popupTextArea;
// if the line above is not working reactively try using vue.set():
// this.$set(this.selectedStudent, this.selectedStudentProperty, this.popupTextArea)
}
}
<tr v-for="s in studentList" :key="index">
<td><input v-model="s.name" /></td>
<td><input v-model="s.description1" #click="selectStudent(s, 'description1')"/></td>
<td><input v-model="s.description2" #click="selectStudent(s, 'description2')"/></td>
</tr>

Jquery dynamically added inputs to form have not POST data PHP

I'm adding <input> fields in form using jquery html() on click event.
$('#container').html('<input type="text" name="ce" value="some" >');
after submitting php POST i'm unable to see index ce with print_r($_POST);
is there any special method to add elements to dom for this ? please advise.
Solved ! Thanks for answering. in my scenario even with append it didn't work. now it's done with my previous code using html(). Problem was wrapping the <form>. my table is large i'm only pointing out the problem. my structure was suppose to like:
<table>
<tr>
<form id="myform">
<td><input type="text" name="name" ></td>
<td>
<div id="container">
<!-- dynamically generated inside this div against it's id (which didn't work) -->
<input type="text" name="ce" >
</div>
</td>
</form>
</tr>
</table>
i simply Put the entire table into the 'form' tags
<form id="myform">
<table>
<tr>
<td><input type="text" name="name" ></td>
<td>
<div id="container">
<input type="text" name="ce" > <!-- dynamically generated inside div (works!) -->
</div>
</td>
</tr>
</table>
</form>
it worked perfectly with both append() and html(). hope will be helpful for someone.
When you do $('#container').html you are not adding a new input, you are replacing all your content with this new input..
try $('#container').append tag
Look at this example -> https://jsfiddle.net/660a3t1g/
$('#myInputs').append('<input type="text" placeholder="LastName: " name="some" >');

How to handle variable number of process variables in Camunda

I'm new to Camunda and didn't find any tutorial or reference explaining how to achieve the following:
When starting a process I want the user to add as many items as he likes to an invoice. On the next user task all those items and their quantity should be printed to somebody approving the data.
I don't understand yet how to get this 1:n relationship between a process and its variables working. Do I need to start subprocesses for each item? Or do I have to use a custom Java object? If so, how can I map form elements to such an object from within the Tasklist?
I got it working with the help of the links provided by Thorben.
The trick is to use JSON process variables to store more complex data structures. I initialize such lists in my "Start Event". This can be done either in a form or in my case in a Listener:
execution.setVariable("items", Variables.objectValue(Arrays.asList(dummyItem)).serializationDataFormat("application/json").create());
Note that I added a dummyItem, as an empty list would lose its type information during serialization.
Next in my custom form I load this list and can add/remove items. Using the camForm callbacks one can persist the list.
<form role="form" name="form">
<script cam-script type="text/form-script">
/*<![CDATA[*/
$scope.items = [];
$scope.addItem = function() {
$scope.items.push({name: '', count: 0, price: 0.0});
};
$scope.removeItem = function(index) {
$scope.items.splice(index, 1);
};
camForm.on('form-loaded', function() {
camForm.variableManager.fetchVariable('items');
});
// variables-fetched is not working with "saved" forms, so we need to use variables-restored, which gets called after variables-fetched
camForm.on('variables-restored', function() {
$scope.items = camForm.variableManager.variableValue('items');
});
camForm.on('store', function() {
camForm.variableManager.variableValue('items', $scope.items);
});
/*]]>*/
</script>
<table class="table">
<thead>
<tr><th>Name</th><th>Count</th><th>Price</th><th></th></tr>
</thead>
<tbody>
<tr ng-repeat="i in items">
<td><input type="text" ng-model="i.name"/></td>
<td><input type="number" ng-model="i.count"/></td>
<td><input type="number" ng-model="i.price"/></td>
<td>
<button class="btn btn-default" ng-click="removeItem($index)">
<span class="glyphicon glyphicon-minus"></span>
</button>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">
<button class="btn btn-default" ng-click="addItem()">
<span class="glyphicon glyphicon-plus"></span>
</button>
</td>
</tr>
</tfoot>
</table>
</form>
Two things aren't working yet:
Field validation, e.g. for number fields
The dirty flag used on the "save" button doesn't get updated, when adding/removing rows