Iam facing some issues while dynamically adding and removing few items using jquery.Currently working on MVC3 project.
Below are the three items that iam adding dynamically to the view (Editor template) using Jquery .
InsuranceType - TextBox
Neighbourhood Area - TextBox
Employment type - TextBox
Delete - Check box
Adding items and deleting items are working fine if iam doing it for the first time.
If i have already added and saved these items then the issue starts.
For example if i have already added and saved three groups of above item three set of these controls(InsuranceType ,Neighbourhood Area,
Employment type,Delete)will be displayed .If i try to delete any of the three item except the last one.While posting to the controller the list is coming as empty.If i delete last item then the other two items are coming in the list.
Issue is there only if i try to delete any previously added items and click on save .
Below is the jquery used while clicking on delete button
$('#Delete').click(function (e) {
$("input[type='checkbox']input[name^='" + data + "']input[name$='Delete']").each(function () {
$(this).closest('span').remove();
});
});
If delete check box is selected .On the click of delete button iam removing the controls.
I tried hiding this instead of removing but its throwing validation error and not allowing user to proceed.
These three fields are required.
Chithra_Iyer
Member
89 Points
414 Posts
Issue while removing dynamically added items
Jan 08, 2013 11:02 AM|LINK
Iam facing some issues while dynamically adding and removing few items using jquery.Currently working on MVC3 project.
Below are the three items that iam adding dynamically to the view (Editor template) using Jquery .
InsuranceType - TextBox
Neighbourhood Area - TextBox
Employment type - TextBox
Delete - Check box
Adding items and deleting items are working fine if iam doing it for the first time.
If i have already added and saved these items then the issue starts.
For example if i have already added and saved three groups of above item three set of these controls(InsuranceType ,Neighbourhood Area,
Employment type,Delete)will be displayed .If i try to delete any of the three item except the last one.While posting to the controller the list is coming as empty.If i delete last item then the other two items are coming in the list.
Issue is there only if i try to delete any previously added items and click on save .
Below is the jquery used while clicking on delete button
$('#Delete').click(function (e) {
$("input[type='checkbox']input[name^='" + data + "']input[name$='Delete']").each(function () {
$(this).closest('span').remove();
});
});
If delete check box is selected .On the click of delete button iam removing the controls.
I tried hiding this instead of removing but its throwing validation error and not allowing user to proceed.
These three fields are required.
Please help me out to resolve this
Many Thanks
asteranup
All-Star
30184 Points
4906 Posts
Re: Issue while removing dynamically added items
Jan 09, 2013 02:13 AM|LINK
Hi,
This can be a selector problem. Can you share your code?
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
Chithra_Iyer
Member
89 Points
414 Posts
Re: Issue while removing dynamically added items
Jan 09, 2013 02:41 AM|LINK
I have shared the code that iam using on click of delete button in my post.
Iam just finding the closest span that has all the controls and then removing it.
will share the complete code
Many Thanks
asteranup
All-Star
30184 Points
4906 Posts
Re: Issue while removing dynamically added items
Jan 09, 2013 04:02 AM|LINK
Hi,
If Delete is the id for multiple delete button, then it will recognize one button only. You can try replacing with some css class.
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog