Get Checkbox value from the database into a table row (MVC) - asp.net-mvc

This may be a simple question but I am new to MVC. So please bear with me.
I want to get the checkbox value into the table row. Here is my code for the table.
<tbody>
#foreach (var itms in Model.takeoverdlist)
{
<tr id="#itms.TAKEOVER_D_id">
<td class="text-left">
<input type="hidden" name="tasklist[]" id="task_id" value="#(itms.TAKEOVER_D_id)" />
</td>
<td class="text-left">
<input type="text" id="task#(itms.TAKEOVER_D_id)" name="task#(itms.TAKEOVER_D_id)" value="#(itms.TAKEOVER_D_task)" style="width:100%" />
</td>
<td class="text-left">
<input type="text" id="amnt#(itms.TAKEOVER_D_id)" name="amnt#(itms.TAKEOVER_D_id)" value="#(itms.TAKEOVER_D_amount)" style="width:100%" />
</td>
<td class="text-left">
<input type="checkbox" id="donebit#(itms.TAKEOVER_D_id)" name="donebit#(itms.TAKEOVER_D_id)" value="#(itms.TAKEOVER_D_done)" style="width:100%" />
</td>
</tr>
}
I get other values just fine, but the checkbox is unchecked. It should be checked.
When I inspect the table the value for the checkbox is "value".

Related

How to dynamically add and remove table rows and add/update them to the database?

I'm working on a project that includes Asp.net Core, Entity Framework and Razor pages. I want to be able to click on an add button and show more table rows that i can fill and update/add to the database.
At this moment there is one table row and if i save it it will add or update to the database. The thing i cant figure out is how to dynamicly add more table rows and add/update them to the database aswell.
We have found a workaround by using an API call and using vue.js but this seems unneeded and there should be an easier way right?
The examples below don't work...
<tbody>
#for (int i = 0; i < Model.BookingModel.HourRows.Count; i++)
{
<tr>
<td><a class="btn-remove-time-row" v-on:click="removeHourRow(index)"><i class="fas fa-times"></i></a></td>
<td class="has-text-input" style="display:none;"><input type="number" class="form-control" placeholder="Werksoort" asp-for="#Model.BookingModel.HourRows[i].Id" value="#Model.BookingModel.HourRows[i].Id" readonly style="display:none;"/></td>
<td class="has-text-input"><input type="number" class="form-control" placeholder="Werksoort" asp-for="#Model.BookingModel.HourRows[i].WorkTypeId" value="#Model.BookingModel.HourRows[i].WorkTypeId" /></td>
<td class="has-text-input"><input type="text" class="form-control" placeholder="Project" asp-for="#Model.BookingModel.HourRows[i].ProjectId" value="#Model.BookingModel.HourRows[i].ProjectId" /></td>
<td class="has-text-input"><input type="number" class="form-control" placeholder="0,00" asp-for="#Model.BookingModel.HourRows[i].Monday" value="#Model.BookingModel.HourRows[i].Monday" /></td>
<td class="has-text-input"><input type="number" class="form-control" placeholder="0,00" asp-for="#Model.BookingModel.HourRows[i].Tuesday" value="#Model.BookingModel.HourRows[i].Tuesday" /></td>
<td class="has-text-input"><input type="number" class="form-control" placeholder="0,00" asp-for="#Model.BookingModel.HourRows[i].Wednesday" value="#Model.BookingModel.HourRows[i].Wednesday" /></td>
<td class="has-text-input"><input type="number" class="form-control" placeholder="0,00" asp-for="#Model.BookingModel.HourRows[i].Thursday" value="#Model.BookingModel.HourRows[i].Thursday" /></td>
<td class="has-text-input"><input type="number" class="form-control" placeholder="0,00" asp-for="#Model.BookingModel.HourRows[i].Friday" value="#Model.BookingModel.HourRows[i].Friday" /></td>
<td class="has-text-input"><input type="number" class="form-control" placeholder="0,00" asp-for="#Model.BookingModel.HourRows[i].Saturday" value="#Model.BookingModel.HourRows[i].Saturday" /></td>
<td class="has-text-input"><input type="number" class="form-control" placeholder="0,00" asp-for="#Model.BookingModel.HourRows[i].Sunday" value="#Model.BookingModel.HourRows[i].Sunday" /></td>
</tr>
}
<tr class="times-row-control">
<td colspan="11">
<button class="btn btn-primary btn-add-time-row" id="addBtn" v-on:click="addHourRow()"><i class="fas fa-plus"></i>Regel toevoegen</button>
</td>
</tr>
</tbody>
addHourRow: function () {
data.booking.hourRows.push({
workTypeId: undefined,
projectId: undefined,
monday: undefined,
tuesday: undefined,
wednesday: undefined,
thursday: undefined,
friday: undefined,
saturday: undefined,
sunday: undefined
})
}
I expect a button which will add a tabelrow to the table and if i fill everything in i expect it to be added or updated to the database.
As you observed, the function addHourRow adds data to a data structure (I can't see what kind) in the browser's page state, but doesn't do anything to change the data at its source, in your database.
To update the database, you'll need to add a request handler to a controller, and call the controller from your javascript code.
This video tutorial of Entity Framework may be useful: https://www.youtube.com/watch?v=ZX7_12fwQLU

URL found in auth.gsp - beginner

I need to know the following. I copied the following code from auth.gsp. I need to know what:
1.) I need to know what '${postUrl}' means?
2.) I did copy this code and paste it in another GSP called index.gsp, but the page didn't login successfully.
<form action='${postUrl}' method='POST' id="loginForm" name="loginForm" autocomplete='off'>
<div class="sign-in">
<h1><g:message code='spring.security.ui.login.signin'/></h1>
<table>
<tr>
<td><label for="username"><g:message code='spring.security.ui.login.username'/></label></td>
<td><input name="j_username" id="username" size="20" /></td>
</tr>
<tr>
<td><label for="password"><g:message code='spring.security.ui.login.password'/></label></td>
<td><input type="password" name="j_password" id="password" size="20" /></td>
</tr>
<tr>
<td colspan='2'>
<input type="checkbox" class="checkbox" name="${rememberMeParameter}" id="remember_me" checked="checked" />
<label for='remember_me'><g:message code='spring.security.ui.login.rememberme'/></label> |
<span class="forgot-link">
<g:link controller='register' action='forgotPassword'><g:message code='spring.security.ui.login.forgotPassword'/></g:link>
</span>
</td>
</tr>
<tr>
<td colspan='2'>
<s2ui:linkButton elementId='register' controller='register' messageCode='spring.security.ui.login.register'/>
<s2ui:submitButton elementId='loginButton' form='loginForm' messageCode='spring.security.ui.login.login'/>
</td>
</tr>
</table>
</div>
</form>
Spring security work on filters. If you print postUrl in your gsp file then it looks like /myApp/j_spring_security_check, only /j_spring_security_check URL is processed by Spring Security filter.
If you past auth.gap and not sending this url then cannot login. Change your gsp slightly to make this run, replace ${postUrl} with ${createLink(uri: '/j_spring_security_check')}.

Nested Form Model in Rails not saving items added with jQuery

I'm following Ryan Bate's RailsCast (#197) for Nested Model Forms.
If I submit a form that has 3 fields added in the controller:
3.times { #prof.experiences.build }
...they save properly. If the field, however, is added via jQuery, it isn't saved.
Has anyone else had experience with this sort of problem before?
EDIT: HTML Generated without jQuery:
<div class="fields">
<table>
<tbody><tr>
<td>Position Title:</td>
<td><input id="applicant_profile_experiences_attributes_0_title" name="applicant_profile[experiences_attributes][0][title]" size="30" type="text"></td>
</tr>
<tr>
<td>Employer:</td>
<td><input id="applicant_profile_experiences_attributes_0_employer" name="applicant_profile[experiences_attributes][0][employer]" size="30" type="text"></td>
</tr>
<tr>
<td>Responsibilities</td>
<td><textarea cols="40" id="applicant_profile_experiences_attributes_0_description" name="applicant_profile[experiences_attributes][0][description]" rows="4"></textarea></td>
</tr>
<tr>
<td>Start Date:</td>
<td><select id="experience_from_date_1i" name="experience[from_date(1i)]">
<option value="1970">1970</option>
<option value="1971">1971</option>
</select>
</td>
</tr>
</tbody></table>
<p><input id="applicant_profile_experiences_attributes_0__destroy" name="applicant_profile[experiences_attributes][0][_destroy]" type="hidden" value="false">Remove</p>
</div>
Code added with jQuery:
<div class="fields">
<table>
<tbody><tr>
<td>Position Title:</td>
<td><input id="applicant_profile_experiences_attributes_1366407307283_title" name="applicant_profile[experiences_attributes][1366407307283][title]" size="30" type="text"></td>
</tr>
<tr>
<td>Employer:</td>
<td><input id="applicant_profile_experiences_attributes_1366407307283_employer" name="applicant_profile[experiences_attributes][1366407307283][employer]" size="30" type="text"></td>
</tr>
<tr>
<td>Responsibilities</td>
<td><textarea cols="40" id="applicant_profile_experiences_attributes_1366407307283_description" name="applicant_profile[experiences_attributes][1366407307283][description]" rows="4"></textarea></td>
</tr>
<tr>
<td>Start Date:</td>
<td><select id="experience_from_date_1i" name="experience[from_date(1i)]">
<option value="1970">1970</option>
<option value="1971">1971</option>
<!-- removed big date list -->
</select>
</td>
</tr>
</tbody></table>
<p><input id="applicant_profile_experiences_attributes_1366407307283__destroy" name="applicant_profile[experiences_attributes][1366407307283][_destroy]" type="hidden" value="false">Remove</p>
</div>

How to show validation errors as a list

I have a simple login form with this code in jsp file:
<s:form
action="conexion" validate="true" theme="xhtml" target="formError">
<s:textfield name="username" key="profile.rut" />
<s:password name="password" key="profile.password" />
<s:submit id="boton_ingreso"/>
</s:form>
when that is rendered, it renders this way:
<form onreset="clearErrorMessages(this);clearErrorLabels(this);" method="post" target="formError" action="/AgendaPlus/conexion.action" onsubmit="return validateForm_conexion();" name="conexion" id="conexion">
<table class="wwFormTable">
<tbody><tr>
<td class="tdLabel"><label class="label" for="conexion_username">RUT:</label></td>
<td><input type="text" id="conexion_username" value="" name="username"></td>
</tr>
<tr>
<td class="tdLabel"><label class="label" for="conexion_password">ContraseƱa:</label></td>
<td><input type="password" id="conexion_password" name="password"></td>
</tr>
<tr>
<td colspan="2"><div align="right"><input type="submit" value="Submit" id="boton_ingreso" class="ui-button ui-widget ui-state-default ui-corner-all" role="button" aria-disabled="false">
</div></td>
</tr>
</tbody></table></form>
That way, when an error occurs, the error is shown above each field with error as a <tr> tag and since it is a table, I cannot style it to move to other place. I tried with target attribute of <s:form> tag but it did not work.
See the tag docs for fielderror:
<s:fielderror />
You know there are other themes, and that you can create your own, right?
For example, the "simple" theme doesn't render any tables or errors.
The target attribute seems a weird use for error reporting.

How to define in Grails an uploadForm and 2 different actions?

I have a gsp view, with an , and 2 input text.
I have a button to save and submit.
Now I would like to add another button with a new action, in my case a button to schedule save.
Note : in my controller I have define : def save (corresponding to button action save) and def schedule (corresponding to button action schedule).
What is the best way to add Schedule in this gsp view :
<g:uploadForm action="save" method="post" >
<div class="dialog">
<table>
<tbody>
<tr class="prop">
<td valign="top" class="name">
<label for="payload">File:</label>
</td>
<td valign="top">
<input type="file" id="payload" name="payload"/>
</td>
<td valign="top">
<input type="file" id="payload2" name="payload2"/>
</td>
</tr>
<tr class="prop">
<td valign="top" class="name">
<label for="lvalue">Lvalue:</label>
</td>
<td valign="top" class="value ${hasErrors(bean:rmmInstance,field:'lvalue','errors')}">
<input type="text" id="lvalue" name="lvalue" value="${fieldValue(bean:rmmInstance,field:'lvalue')}" />
</td>
</tr>
<tr class="prop">
<td valign="top" class="name">
<label for="wvalue">Wvalue:</label>
</td>
<td valign="top" class="value ${hasErrors(bean:rmmInstance,field:'wvalue','errors')}">
<input type="text" id="wvalue" name="wvalue" value="${fieldValue(bean:rmmInstance,field:'wvalue')}" />
</td>
</tr>
</tbody>
</table>
</div>
<div class="buttons">
<span class="button"><input class="save" type="submit" value="Run Now" /></span>
</div>
</g:uploadForm>
I have just one form, but 2 different actions.
Thanks !
With an actionSubmit:
Purpose
Creates a submit button that maps to a
specific action, which allows you to
have multiple submit buttons in a
single form. Javascript event handlers
can be added using the same parameter
names as in HTML.
From the Grails reference docs.

Resources