i am using https://developer.snapappointments.com/bootstrap-select/examples/
its working fine in view but when i using this in Jquery below code its not working. help me to fix this.
view code
<table id="tableAppointment" style="background-color:powderblue;">
<tr>
<th style="text-align:center;" colspan="1">NAME</th>
<th style="text-align:center;" colspan="1">HSN/SAC</th>
<th><i class="glyphicon glyphicon-plus">ADD</i></th>
</tr>
<tr>
<td >
<select class="selectpicker" data-live-search="true" name="product_name[]">
<option value=""></option>
#foreach ($addnewitem as $key=>$addnewitems)
<option >{{$addnewitems->product_name}}</option>
#endforeach </select>
</td>
<td >
<select class="selectpicker" data-live-search="true" name="part_no[]">
<option value=""></option>
#foreach ($addnewitem as $key=>$addnewitems)
<option >{{$addnewitems->part_no}}</option>
#endforeach </select>
</td>
<td><i class="glyphicon glyphicon-remove">REMOVE</i></td>
</tr>
</table>
<script type="text/javascript">
$('.addRow').on('click',function(){
addRow();
});
function addRow()
{
var tr='<tr>'+
'<td ><select class="selectpicker" data-live-search="true" name="product_name[]"><option
value=""></option> #foreach($addnewitem as $key=>$addnewitems)<option >{{$addnewitems->product_name}}</option>#endforeach </select></td>'+
'<td ><select class="selectpicker" data-live-search="true" name="part_no[]"><option value=""></option> #foreach($addnewitem as $key=>$addnewitems)<option >{{$addnewitems->part_no}}</option>#endforeach </select></td>'+
'<td><i class="glyphicon glyphicon-remove">REMOVE</i></td>'+
'</tr>';
$('tbody').append(tr);
};
$('.remove').live('click',function(){
var last=$('tbody tr').length;
if(last==1){
alert("you can not remove last row");
}
else{
$(this).parent().parent().remove();
}
});
</script>
after click $('.addRow') u need to re-render selectpicker
You can force a re-render of the bootstrap-select ui with the render method. This is useful if you programatically change any underlying values that affect the layout of the element.
$(document).on('click','.addRow',function(){
addRow();
$('.selectpicker').selectpicker('refresh');
});
Related
I have this HTML code :
<table>
<tr>
<td colspan="2">
<input type="radio" name="lineChoice" id="lineChoiceA" value="A"><label for="lineChoiceA">Line A</label>
<input type="radio" name="lineChoice" id="lineChoiceB" value="B"><label for="lineChoiceB">Line B</label>
</td>
</tr>
<tr id="lineA" style="display: none;">
<td>List A : </td>
<td>
<select name="mySelect" id="mySelect">
<option value=""></option>
<option value="A0">A0</option>
<option value="A1">A1</option>
<option value="A2">A2</option>
</select>
</td>
</tr>
<tr id="lineB" style="display: none;">
<td>List B : </td>
<td>
<select name="mySelect" id="mySelect">
<option value=""></option>
<option value="B0">B0</option>
<option value="B1">B1</option>
<option value="B2">B2</option>
</select>
</td>
</tr>
</table>
And I have this JQuery code :
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
$(function(){
// If Click on Radio
$('[id^="lineChoice"]').click(function(){
// Hide Line
$("#lineA").hide();
$("#lineB").hide();
// Display Line
if($(this).val()=="A") $("#lineA").show();
if($(this).val()=="B") $("#lineB").show();
});
// If Change on List
$('#mySelect').change(function(){
// Just Display in Console
console.log($(this).val());
});
});
</script>
Both lines are basically hidden.
And by selecting the radio button I display the corresponding line. I voluntarily simplified the name of the lines (it is more complex in my initial code).
If I select row A. Display in JQuery works fine. But I get nothing if I select line B. I know that my "select" have the same name but that's precisely the goal for me. Have only one "select" to process but only the displayed one.
Hoping to be clear in my question which is "Why no display when selecting line B while it works with line A...?
You cannot have two elements with the same id within one page. Hence I update your code using different Ids for the two selects.
In order to register the event using the name, you can use the attribute selector instead. [name="mySelect"] would do the trick.
The reason why the change event is not working on line B is because $('#mySelect').change(function(){}) only register the event on the first select which turn out is the Line A <select>
$(document).ready(() => {
$('input[type="radio"]').on('change', (e) => {
$("#lineA").hide();
$("#lineB").hide();
if (e.currentTarget.id === 'lineChoiceA') {
$("#lineA").show();
} else {
$("#lineB").show();
}
})
// If Change on List
$('[name="mySelect"]').change(function() {
// Just Display in Console
console.log($(this).val());
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<td colspan="2">
<input type="radio" name="lineChoice" id="lineChoiceA" value="A"><label for="lineChoiceA">Line A</label>
<input type="radio" name="lineChoice" id="lineChoiceB" value="B"><label for="lineChoiceB">Line B</label>
</td>
</tr>
<tr id="lineA" style="display: none;">
<td>List A : </td>
<td>
<select name="mySelect" id="mySelect1">
<option value=""></option>
<option value="A0">A0</option>
<option value="A1">A1</option>
<option value="A2">A2</option>
</select>
</td>
</tr>
<tr id="lineB" style="display: none;">
<td>List B : </td>
<td>
<select name="mySelect" id="mySelect2">
<option value=""></option>
<option value="B0">B0</option>
<option value="B1">B1</option>
<option value="B2">B2</option>
</select>
</td>
</tr>
</table>
How i can add input field on specific selection in depended drop down
i want to show input field when user select other option in drop down list.
Like when someone want to add something more that is not in the list he can add manually.
List will be too big I'm just showing the first three categorizes
Here is my code:
#extends('layout/header')
#include('layout/sidebar')
<div id="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<h1 class="motetreports_heading"></h1>
{{-- first sequnce --}}
<form action="/atgard" method="post">
#csrf
<table width="50%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="41%" align="right" valign="middle">Category1 :</td>
<td width="59%" align="left" valign="middle">
<select name="category1" id="category1">
<option value="">Select Category1</option>
<option value="home_ware">Home Ware</option>
<option value="education">Education</option>
<option value="books">Other</option>
</select>
</td>
</tr>
<tr>
<td align="right" valign="middle">Category2 :</td>
<td align="left" valign="middle">
<select disabled="disabled" class="subcat" id="category2" name="category2">
<option value>Select Category2</option>
<!-- Home Ware -->
<optgroup data-rel="home_ware">
<option value="air-conditioners_coolers">Air-Conditioners/Coolers</option>
<option value="audio-video">Audio/Video</option>
<option value="beddings">Beddings</option>
<option value="camera">Camera</option>
<option value="cell-phones">Cell Phones</option>
</optgroup>
<!-- Education -->
<optgroup data-rel="education">
<option value="Colleges">Colleges</option>
<option value="Institutes">Institutes</option>
<option value="Schools">Schools</option>
<option value="Tuitions">Tuitions</option>
<option value="Universities">Universities</option>
</optgroup>
<!-- Books -->
<optgroup data-rel="books">
<option value="College Books">College Books</option>
<option value="Engineering">Engineering</option>
<option value="Magazines">Magazines</option>
<option value="Medicine">Medicine</option>
<option value="References">References</option>
</optgroup>
</select>
</td>
</tr>
<tr>
<td align="right" valign="middle">Category3 :</td>
<td align="left" valign="middle">
<select disabled="disabled" class="subcat" id="category3" name="category3">
<option value>Select Category3</option>
<!-- Home Ware -->
<optgroup data-rel="home_ware">
<option value="foo1">category3 home ware 1</option>
<option value="foo2">category3 home ware 2</option>
</optgroup>
<!-- Education -->
<optgroup data-rel="education">
<option value="foo3">category3 Education 1</option>
<option value="foo4">category3 Education 2</option>
</optgroup>
<!-- Books -->
<optgroup data-rel="books">
<option value="foo5">category3 Books 1</option>
<option value="foo6">category3 Books 2</option>
</optgroup>
</select>
</td>
</tr>
</table>
<button type="submit" style="width: 100px;" class="btn btn-primary">Skicka</button>
</form>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var $cat = $("#category1"),
$subcat = $(".subcat");
var optgroups = {};
$subcat.each(function(i,v){
var $e = $(v);
var _id = $e.attr("id");
optgroups[_id] = {};
$e.find("optgroup").each(function(){
var _r = $(this).data("rel");
$(this).find("option").addClass("is-dyn");
optgroups[_id][_r] = $(this).html();
});
});
$subcat.find("optgroup").remove();
var _lastRel;
$cat.on("change",function(){
var _rel = $(this).val();
if(_lastRel === _rel) return true;
_lastRel = _rel;
$subcat.find("option").attr("style","");
$subcat.val("");
$subcat.find(".is-dyn").remove();
if(!_rel) return $subcat.prop("disabled",true);
$subcat.each(function(){
var $el = $(this);
var _id = $el.attr("id");
$el.append(optgroups[_id][_rel]);
});
$subcat.prop("disabled",false);
});
});
</script>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
#include('layout/footer')
I think you should put an document.getElementById("theselectid").selected = true; or something that will indicate that it was checked, then: inside if, document.getElementById("theidofinput").disabled = false;document.getElementById("theidofinput").style.opacity = 1.0; or something.
I am creating a vehicle lookup service for visitors to my employer's website. By entering their vehicle details either manually or by entering their reg, the site products will be filtered to match fitment for that specific vehicle.
If the customer enters their reg and clicks submit, the results are captured in a hidden table on the same page. I want the manual selector values to update according to such hidden values.
How would I get the search data to show in the appropriate selector option? (I understand that none of the results is an option but if it was then how would I do it)
Here is the manual vehicle details code:
<div class="block-content">
<div class="level">
<select class="ymm-select" name="_make">
<option value="">-- Make --</option>
<option value="BMW">BMW</option>
</select>
</div>
<div class="level">
<select class="ymm-select disabled" name="_model" disabled="disabled">
<option value="">-- Model --</option>
</select>
</div>
<div class="level">
<select class="ymm-select disabled" name="_year" disabled="disabled">
<option value="">-- Year --</option>
</select>
</div>
<div class="ymm-clear"> </div>
<div class="ymm-extra" style="display:none">
<div class="ymm-category-container">
<div class="ymm-clear"> </div>
</div>
</div>
<button type="button" title="Search" class="button ymm-submit-any-selection">Search</button>
</div>
Here is the vehicle result data:
<table class="table" hidden="">
<tbody>
<tr>
<td>Make:</td>
<td id="dvla-search-make">FORD </td>
</tr>
<tr>
<td>Model:</td>
<td id="dvla-search-model">FOCUS</td>
</tr>
<tr>
<td>Year:</td>
<td id="dvla-search-year">2009</td>
</tr>
<tr>
<td>Engine:</td>
<td id="dvla-search-engine">1753cc</td>
</tr>
<tr>
<td id="dvla-search-fuel">Fuel Type:</td>
<td>DIESEL</td>
</tr>
</tbody>
</table>
You mean something like this?
window.addEventListener("load",() => { // when the page loads
document.querySelectorAll("[id^=dvla-search]").forEach(entry => { // find all table cells with ids starting with dvla-search
const val = entry.innerText.trim();
const name = entry.id.replace("dvla-search-","_"); // find the name of the
const elem = document.querySelector("[name="+name+"]") // select associated with the cell id
if (elem) { // if found
let vals = [...elem.querySelectorAll("option")].map(opt => opt.value)
if (!vals.includes(val)) { // only add if not already there
const opt = new Option(val,val,true,true); // make an option and select it
elem.appendChild(opt); // add the option
elem.removeAttribute("disabled"); // allow selection
}
else elem.value=val; // IF already there, select it
}
})
});
Here is the manual vehicle details code:
<div class="block-content">
<div class="level">
<select class="ymm-select" name="_make">
<option value="">-- Make --</option>
<option value="FORD">FORD</option>
</select>
</div>
<div class="level">
<select class="ymm-select disabled" name="_model" disabled="disabled">
<option value="">-- Model --</option>
</select>
</div>
<div class="level">
<select class="ymm-select disabled" name="_year" disabled="disabled">
<option value="">-- Year --</option>
</select>
</div>
<div class="ymm-clear"> </div>
<div class="ymm-extra" style="display:none">
<div class="ymm-category-container">
<div class="ymm-clear"> </div>
</div>
</div>
<button type="button" title="Search" class="button ymm-submit-any-selection">Search</button>
</div>
Here is the vehicle result data:
<table class="table" hidden="">
<tbody>
<tr>
<td>Make:</td>
<td id="dvla-search-make">FORD </td>
</tr>
<tr>
<td>Model:</td>
<td id="dvla-search-model">FOCUS</td>
</tr>
<tr>
<td>Year:</td>
<td id="dvla-search-year">2009</td>
</tr>
<tr>
<td>Engine:</td>
<td id="dvla-search-engine">1753cc</td>
</tr>
<tr>
<td id="dvla-search-fuel">Fuel Type:</td>
<td>DIESEL</td>
</tr>
</tbody>
</table>
I am using DataTables on a HTML table and would like to hide all select and inputs from the table headings.
I have used this code:
#media print{
th select{
display: none;
}
}
But that didn't work.
One example is, in 1 column I have this as the heading:
<th>
All Businesses
<select name='business' id='business'>
<option value=''>All Businesses...</option>
<option value='Business 1'>Business 1</option>
<option value='Business 2'>Business 2</option>
<option value='Business 3'>Business 3</option>
</select>
</th>
Which when printing looks like this:
Ideally I need a solution that means the select isn't in the TH but is in the same position as it is now (just under the "All Businesses" bit). I say this because DataTables has a visibility column which ends up using everything in the th meaning the business names show up in that as well.
Thanks!
This is the full code for the table head:
$label_to_name = array();
$tableRes = $db->query("SELECT * from staff_fields");
$table = "<table class='table' id='table'><thead><tr><th>All Businesses<select name='business' id='business'><option value=''>All Businesses...</option><option value='Business 1'>Business 1</option><option value='Business 2'>Business 2</option><option value='Business 3'>Business 3</option></select></th>";
$trowss = $tableRes->fetchAll(PDO::FETCH_ASSOC);
$js = "";
$i = 1;
foreach($trowss as $trows){
if($trows['type'] == "yesno"){
$search_option = "<select id='".$trows['name']."' name='".$trows['name']."'><option value=''>Select Filter...<option value='Yes'>Yes</option><option value='No'>No</option></select>";
$js .= "var ".$trows['name']."index = ".$i.";
$('#".$trows['name']."').on('change',function(){
oTable.columns(".$trows['name']."index).search($(this).val()).draw();
});
";
}else{
$search_option = "<input type='text' name='".$trows['name']."' id='".$trows['name']."' placeholder='Type to Search...'>";
$js .= "var ".$trows['name']."index = ".$i.";
$('#".$trows['name']."').on('input',function(){
oTable.columns(".$trows['name']."index).search($(this).val()).draw();
});
";
}
$table .= "<div class='table_heading'><th>".$trows['label']."</th>".$search_option."</div>";
$label_to_name[$trows['label']] = $trows['name'];
$i++;
}
$table .= "</tr></thead><tbody>";
HTML Output:
<table class='table' id='table'>
<thead>
<tr>
<th>
All Businesses
<select name='business' id='business'>
<option value=''>All Businesses...</option>
<option value='Business 1'>Business 1</option>
<option value='Business 2'>Business 2</option>
<option value='Business 3'>Business 3</option>
</select>
</th>
<th>First Name<input type='text' name='first_name1459057776924' id='first_name1459057776924' placeholder='Type to Search...'></th>
<th>Last Name<input type='text' name='last_name1459057788088' id='last_name1459057788088' placeholder='Type to Search...'></th>
<th>Job Title<input type='text' name='job_title1459057796608' id='job_title1459057796608' placeholder='Type to Search...'></th>
<th>
Proof of Age on File
<select id='proof_of_age_on_file1459057805910' name='proof_of_age_on_file1459057805910'>
<option value=''>Select Filter...
<option value='Yes'>Yes</option>
<option value='No'>No</option>
</select>
</th>
<th>Date of Birth<input type='text' name='date_of_birth1459057814082' id='date_of_birth1459057814082' placeholder='Type to Search...'></th>
<th>Start Date<input type='text' name='start_date1459057824504' id='start_date1459057824504' placeholder='Type to Search...'></th>
<th>
Signed Contract in Place
<select id='signed_contract_in_place1459057835607' name='signed_contract_in_place1459057835607'>
<option value=''>Select Filter...
<option value='Yes'>Yes</option>
<option value='No'>No</option>
</select>
</th>
<th>
DBS on File
<select id='dbs_on_file1459057844504' name='dbs_on_file1459057844504'>
<option value=''>Select Filter...
<option value='Yes'>Yes</option>
<option value='No'>No</option>
</select>
</th>
<th>DBS Date<input type='text' name='dbs_date1459057856098' id='dbs_date1459057856098' placeholder='Type to Search...'></th>
<th>
References Received
<select id='references_received1459057869650' name='references_received1459057869650'>
<option value=''>Select Filter...
<option value='Yes'>Yes</option>
<option value='No'>No</option>
</select>
</th>
<th>
Payroll Info Given to HO
<select id='payroll_information_given_to_ho1459057881692' name='payroll_information_given_to_ho1459057881692'>
<option value=''>Select Filter...
<option value='Yes'>Yes</option>
<option value='No'>No</option>
</select>
</th>
<th>Leaving Date<input type='text' name='leaving_date1459057889857' id='leaving_date1459057889857' placeholder='Type to Search...'></th>
<th>
Left
<select id='left1459263499753' name='left1459263499753'>
<option value=''>Select Filter...
<option value='Yes'>Yes</option>
<option value='No'>No</option>
</select>
</th>
<th>Next Of Kin (Name, Relationship and Contact Number)<input type='text' name='next_of_kin1459342113034' id='next_of_kin1459342113034' placeholder='Type to Search...'></th>
<th>Medical Condition<input type='text' name='medical_condition1459342141909' id='medical_condition1459342141909' placeholder='Type to Search...'></th>
</tr>
</thead>
The problem that you have is not with your css, but with your HTML.
You should make sure that your <th> tag is inside a <table> <tr> tag, otherwise the browser will change your structure and the #media print will not apply.
You can always check that your html structure is valid using the w3 validator.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test</title>
<style type="text/css">
#media print {
th select {
display: none;
}
}
</style>
</head>
<body>
<table>
<tr>
<th>
All Businesses
<select name='business' id='business'>
<option value=''>All Businesses...</option>
<option value='Business 1'>Business 1</option>
<option value='Business 2'>Business 2</option>
<option value='Business 3'>Business 3</option>
</select>
</th>
</tr>
</table>
</body>
</html>
I have a elemetn in my page. I don't control all javascripts used in this page, and seems that in some place my "select" element is being parsed by dojo and changed to a dijit element (dijit.form.select).
This element does not have an attribute "data-dojo-type", so I don't know why it is being changed.
Is there someway to avoid dojo parse this element?
<tr>
<th scope="row"><div dojoType="dijit.InlineEditBox">Stuff</div></th>
<td>
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</td>
</tr>
I can't see the problem you have in this jsfiddle. The InlineEditBox becomes a dijit, but the <select> does not. The example can try both Dojo 1.6.0 and Dojo 1.8.3:
HTML:
<script>
var dojoConfig = {
parseOnLoad: false
};
</script>
<script>
var v16 = "https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js.uncompressed.js";
var v18 = "https://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/dojo.js";
var dojoUrl = v18;
document.writeln("<script src='" + dojoUrl + "'></scr" + "ipt>");
</script>
<table border="1">
<tr>
<th scope="row">
<div id="inlineEditBox1" dojoType="dijit.InlineEditBox">Stuff</div>
</th>
<td>
<select id="select1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</td>
</tr>
</table>
JS:
function dojo16ready() {
if (!(dojoConfig && dojoConfig.parseOnLoad)) {
dojo.parser.parse();
}
}
function dojo18ready(parser, registry) {
function go() {
console.log("inlineEditBox1", registry.byId("inlineEditBox1"));
console.log("select1", registry.byId("select1"));
}
if (!(dojoConfig && dojoConfig.parseOnLoad)) {
parser.parse().then(go);
}
}
function init() {
console.log("dojo.version", dojo.version);
if ("function" !== typeof require) {
// Must require before onload
dojo.require("dijit.InlineEditBox");
dojo.addOnLoad(dojo16ready);
} else {
require(["dojo/parser", "dijit/registry", "dijit/InlineEditBox"], dojo18ready);
}
}
init();