Thymeleaf table - spring-boot

I have problem table when i want set value with for each i.index get error java.lang.NumberFormatException: For input string: "${i.index}". In Array i need numer so ${i.index} is int. I dont know what i do wrong.
<div class="form-group row" th:each="attribute, i: ${attributeList}">
<label class="col-sm-3 col-form-label" th:text="${attribute.name}"></label>
<div class="col-sm-9">
<input type="text" th:field="*{technicalAttributes[${i.index}].name}" class="form-
control" placeholder="Nazwa">
</div>
</div>

You can't nest expressions (*{...${...}...}) like you're doing without using preprocessing. Your code should look like this:
<div class="form-group row" th:each="attribute, i: ${attributeList}">
<label class="col-sm-3 col-form-label" th:text="${attribute.name}"></label>
<div class="col-sm-9">
<input type="text" th:field="*{technicalAttributes[__${i.index}__].name}" class="form-control" placeholder="Nazwa">
</div>
</div>
(If you weren't using the th:field attribute, the expression *{technicalAttributes[i.index].name} would also be appropriate. But since you are using a th:field you have to use preprocessing.)

Related

Unable to exclude the last element in xpath

I have roughly the following html:
<div class="form-group row">
<label class="control-label col-md-2 font-weight-bold text-right" for="Name">Name</label>
<div class="col-md-10">
<input class="form-control text-box single-line valid" data-val="true" id="Name" name="Name" type="text" value="Mark"
<span class="text-danger field-validation-valid"</span>
</div>
</div>
<div class="form-group row">
<label class="control-label col-md-2 font-weight-bold text-right" for="Address">Address</label>
<div class="col-md-10">
<input class="form-control text-box single-line valid" data-val="true" id="Address" name="Address" type="text" value="101 Windmere"
<span class="text-danger field-validation-valid"</span>
</div>
</div>
<div class="form-group row">
<label class="control-label col-md-2 font-weight-bold text-right" for="Notes">Notes</label>
<div class="col-md-10">
<input class="form-control text-box single-line valid" data-val="true" id="Notes" name="Notes" type="text" value="Sample note goes here"
<span class="text-danger field-validation-valid"</span>
</div>
</div>
<div class="form-group row">
<label class="control-label col-md-2 font-weight-bold text-right" for="Award">Award</label>
<div class="col-md-10">
<input class="form-control text-box single-line valid" data-val="true" id="Award" name="Award" type="text" value="20"
<span class="text-danger field-validation-valid"</span>
</div>
</div>
As you may be able to tell, I am dealing with a form table of sorts. I am trying to iterate over this and grab all the values. I need all the instances of "col-md-10" except the last one (Award). So I am using the following xpath:
//div[#class = 'col-md-10'][position()<4]
However, it keeps finding all four instances and doesn't stop at 3. No matter what number I put in for position. Even if I do [position()<1], it finds all four.
Any ideas?
The <span> tags in your html aren't closed properly (they should be <span/>). That aside, the following expression should get you there:
(//div[#class = 'col-md-10'])[position()<4]

How would I display a single form label with the required class above two text fields using Laravel and Bootstrap 4

I'm using Laravel and Bootstrap 4.2.1 and would like to display a form label over two required in-line text fields. I can get the label over the two fields by placing the form label outside of a form group but I am unable to get the red asterisk (*) display next to the form label. I've placed my code here in jsfiddle.
<label for="contact_first_name" class="form-label required">Contact Name</label>
<div class="form-group mb-3">
<div class="row">
<div class="col-md-6">
<input class="form-control" id="contact_first_name" name="contact_first_name" type="text"
placeholder="First Name" value="" required>
</div>
<div class="col-md-6">
<input class="form-control" id="contact_last_name" name="contact_last_name" type="text"
placeholder="Last Name" value="" required>
</div>
</div>
</div>
Try adding a span tag with class="text-danger" or style="color:red" inside the label tag and the * in it. Either way, you will get an * sign with the label.
Below, I have used the bootstrap approach of adding class="text-danger" to the span tag.
<label for="contact_first_name" class="form-label required">Contact Name
<span class="text-danger">*</span>
</label>
<div class="form-group mb-3">
<div class="row">
<div class="col-md-6">
<input class="form-control" id="contact_first_name" name="contact_first_name" type="text"
placeholder="First Name" value="" required>
</div>
<div class="col-md-6">
<input class="form-control" id="contact_last_name" name="contact_last_name" type="text"
placeholder="Last Name" value="" required>
</div>
</div>
</div>
Here is the link to the Jsfiddle.
#AhmadKarimi Thank you for your comment and solution. I just figured it out (by accident) while working on a different form. I needed to drop the label form control down one level inside of the form-group. It doesn't appear to work in jfiddle though.
<div class="form-group mb-3">
<label for="contact_first_name" class="form-label required">Contact Name</label>
<div class="row">
<div class="col-md-6">
<input class="form-control" id="contact_first_name"
name="contact_first_name" type="text"
placeholder="First Name" value="" required>
</div>
<div class="col-md-6">
<input class="form-control" id="contact_last_name"
name="contact_last_name" type="text"
placeholder="Last Name" value="" required>
</div>
</div>
</div>

view new div based on option value of select tag using laravel

i have a dropdown list when i select any one option from list i should display an another form with name of the teacher and subject of the teacher in textbox.The form is not displaying.when i select one item it should display the selected name and description box to add subjects of teachers that they interested please help me
view page
<div class="portlet light bordered row">
<h1>Add teacher subject</h1>
<div class="row">
<form action = "{{ url('subjectby/adding/process') }}" method = "POST">
{{ csrf_field() }}
<div class= "col-md-12">
<div class="form-group">
<h3>Choose Teachers </h3>
<div class="input-group">
<div class="ui-widget border-dropdown" style="margin-left:50px;">
<select id="teacher" name="teachers" placeholder="Select Teacher">
<option value="">Select Teacher</option>
#foreach($user as $tec)
<option value="{{$tec->id}}">{{$tec->name}}</option>
#endforeach
</select>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="new">
<div class="form-group">
<div class="col-sm-6">
<label for="inputFacebook">Teacher Name</label>
<input type=hidden value="{{$tec->id}}" name="id">
<input type="text" value="{{$tec->name}}" class="form-control" name="name">
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<label for="inputDescription">Subject Interested</label>
<textarea class="form-control" rows="8" name="intr" placeholder="Enter Subject Interest"> </textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<input type="submit" value="add" name=b1>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
This isn't a Laravel specific problem. You are taking about DOM manipulation and so you best bet is to use jQuery or Vuejs or even vanilla Javascript if you so choose. Basically, you will write a script to watch for when your <select> changes, and then based on it's new value, show the part of the form you want.
Keep in mind that Laravel is a backend framework and so the user will never interact with it on a page. After a page loads, Laravel has done all it can do until another request is made. This is why Javascript was born - to let the user change things without reloading the page.

Bootstrap form validator

I am new to Bootstrap 3. I am creating a login page and I have this code:
* I got this generated from Bootply.
<form class="form-horizontal">
<fieldset>
<!-- Form Name -->
<legend>Registry Login</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="input_email">Email</label>
<div class="col-md-8">
<input id="input_username" name="input_email" placeholder="" class="form-control input-md" required="" type="email">
</div>
</div>
<!-- Password input-->
<div class="form-group">
<label class="col-md-4 control-label" for="input_password">Password</label>
<div class="col-md-8">
<input id="input_password" name="input_password" placeholder="" class="form-control input-md" required="" type="password">
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for=""></label>
<div class="col-md-4">
<button id="" name="" class="btn btn-default">Login</button>
</div>
</div>
</fieldset>
</form>
I keyed in on my Email field this sample string abcde and I received a small tooltip saying that Please enter an email address. Is there a way for me to change the text?
You'll have to change the form options with Codeigniter, I'm not too familiar with it, but it sounds like it would be under a submit code for a post.

xpath - how can I select the checkbox based on the text before it

I have text that says 'Roles'. After that there are two checkboxes.
I can get to 'Roles'.
How can I get to and click check the checkboxes?
I am trying to use:
xpath=(//label[contains(text(),'Roles')]/div/span/input)
but getting not found.
My HTML is:
<div class="control-group string required">
<label class="string required control-label" for="survey_name">
<abbr title="required">*</abbr> Name</label>
<div class="controls">
<input class="string required" id="survey_name" name="survey[name]" size="50" type="text" /></div>
</div>
<div class="control-group check_boxes required">
<label class="check_boxes required control-label">
<abbr title="required">*</abbr> Roles
</label>
<div class="controls">
<span class="checkbox">
<input class="check_boxes required" id="survey_role_ids_121" name="survey[role_ids][]" type="checkbox" value="121" />
</span>
</div>
</div>
</div>
The div is not a child of the label, is is a following-sibling. Therefore, the XPath expression you need is
//label[contains(., "Roles")]/following-sibling::div/span/input

Resources