Adding value in input text field using Rails 3 - ruby

I have a small problem.I want to add value inside the input text field which is fetching from DB.
Suppose i have a input field like below.
<input type="text" class="form-control" placeholder="Receipt No">
I have to add #user.Receipt_No inside it as its value.This value is fetching from user table of DB.Please help me resolve this problem.

Try this,
<input type="text" class="form-control" placeholder="Receipt No" value="<%= #user.Receipt_No %>">

Related

How Can i keep a fix Standard Date Format regardless of any Locale

I am trying to keep the Date format to Standard locale "en" regardless of whatever the locale is but it's changing as the locale get change.
I am using thymeleaf 3 ,
for simple text display field i fixed it as
note* i am using java.util.date
<td th:text="${#temporals.format(T(java.time.LocalDate).of(#dates.year(birthdate), #dates.month(birthdate), #dates.day(birthdate)), 'dd-MM-yyyy', new java.util.Locale('en', 'EN'))}"></td>
but the problem i am facing is during form updating when the locale is not set to standard("en"). then the input field doesn't show up the value and just show the date format .
<input type="date" class="form-control" required="required" th:field="*{{birthDate}}" name="birthDate">
<input type="date" class="form-control" required="required" th:field="*{{registrationDate}}" name="registrationDate">
And during editing the form i get my dates like this
any help would be appreciated ! thanks
I fixed it for the input fields too
<input type="date" class="form-control" id="txtDateOfBirthAdd" required="required"
th:value="${employee.birthDate}?${#temporals.format(T(java.time.LocalDate).of(#dates.year(employee.birthDate), #dates.month(employee.birthDate), #dates.day(employee.birthDate)), 'yyyy-MM-dd', new java.util.Locale('en', 'EN'))}:''"
name="birthDate"
placeholder="Date of Birth">
now i have fixed date pattern no matter whatever the locale is . .

Laravel validator on a form and send post

I used laravel validator.
I have a form wih 2 fields
If i fill one field "NAME" and i leave the other "SURNAME" empty pressing SAVE button of the form appears required alert message on SURNAME but the name inserted in the NAME field became empty! And i think form send data anyway.why?I aspect that form doesn't send datas
In the value attribute of each input you need to echo old("the-input-name") so it can retain the previous input before the error
<input name="name" value="{{old('name')}}" class="" />
You should use old('NAME') to get the value of the field after the validation fails, blade example:
<input type="text" value="{{ old('NAME') }}" />
An example In case of update forms you should display the original value from the database unless there's an error:
<input type="text" value="{{ old('NAME') ?? $your_entry->value }}" />
Take a look at the documentation for more details

How to set default value in thymeleaf th:field

I have a form and I want to set default value in the field below but it's not working.
<span>ID User:</span>
<input type="text" th:value="${session.name}" th:field="*{userid}" th:errorclass="field-error" />
</div>
<div>
<span class="name-in">ID Room:</span>
<input type="text" th:value="${id}" th:field="*{room}" th:errorclass="field-error" />
</div>
I read some topic about this problem and I try to change as given below
th:attr="value = ${session.name}"
But It's still not working. Field ID User is empty. I don't know how to solve this problem.
Although your question contain less information, but i think you want to put default value for all field. If you like to do so change
`<input type="text" th:value="${session.name}" th:field="*{userid}" th:errorclass="field-error" />`
to
<input type="text" name="userid" value="as your wish" th:errorclass="field-error" />
Instead of changing the html, you should instead set the value of *{userid} in your controller. That way you can keep your html the same:
// Controller
modelObject.setUserId(session.name);
// HTML
<input type="text" th:field="*{userid}" th:errorclass="field-error" />

Edit Form (Laravel 5.3)

I am using same form for Create and Edit i have a Folder field and i want to set its value Inbox by default however if a user want to replace it with own folder he /she can replace
<input type="text" name="folder" value="INBOX {{isset($mbl->folder) ? $mbl->folder : '' }}" class="form-control" />
when i go on edit it shown **INBOX INBOX
I want that Default value should not be show in Edit form it just show the name from Folder remember that i can't remove value="INBOX" because i need it i am using it as default value and i am using same form for Create and Edit
Thanks For Help
You Need to pass default value as
<input type="text" name="folder" value="{{isset($mbl->folder) ? $mbl->folder : 'INBOX' }}" class="form-control" />
Try This hope it will work
Simply use it as follows:
<input type="text" name="folder" value="{{$mbl->folder or 'INBOX' }}" class="form-control" />
More info here.

MVC3 Validation on edit

I am having a problem with my client side validating. I am using DataAnnotations in my model. An this works when i am in the create form very nicely, but when i go to edit the information only some of the validation works.
i.e the Name box does have clientside val but the amount box does.
i have check the source name doesnot include the data-val="true". I don't understand why this would render this way because on the 'create' form it does and works fine?
<input class="text-box single-line" id="Name" name="Name" type="text" value="name" />
<span class="field-validation-valid" data-valmsg-for="Name" data-valmsg-replace="true"></span>
<input class="text-box single-line" data-val="true" data-val-number="The field Amount must be a number." data-val-required="The Amount field is required." id="Amount" name="Amount" type="text" value="120.00" />
<span class="field-validation-valid" data-valmsg-for="Amount" data-valmsg-replace="true"></span>
can somebody give me an idea how to make my 'edit' page validation work?
Thanks in advance
thank you for the help. but is have solved it!!
The problem was that because i was generated the edit view from the wrong class which meant that the DataAnnotations was not being read. what is have done now is to change the name of the class to that of my database then mark the class as partial and connected the DataAnnotaions by using this code below
[MetadataType(typeof(Budget_Validation))]
public partial class Budget
I put all the dataAnnotaions in the Budget_Validation class.
All now working fine!
Thanks

Resources