I am developing a system I have been asked to do but the form elements are not clickable to enter any info in the fields, I have tried moving the form tag to above the very first div in the code below in case it was the issue but did not work unfortunately. I am not sure what else to try, can someone have a look at the code below please
Update: I have got the form elements working by adding zindex: 9999; to .form-group class in the CSS but now the datetimepicker is appearing behind the select dropdown menu. I have uploaded a screenshot of the issue to the link below
Here is a screenshot of my issue:
My code:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-lg-12" id="detail">
<form name="addData" id="addData" action="" method="post">
<div class="row">
<div class="form-group col-lg-3">
<input type="hidden" name="eventID" id="eventID" class="form-control">
<label for="StartDate">Start Date: </label>
<input type="date" class="form-control" required name="StartDate" id="StartDate" />
</div>
<div class="form-group col-lg-3">
<label for="StartTime" style="margin: 0 0 15px 0;">Start Time: </label>
<div class='input-group date' id='datetimepicker3'>
<input name="StartTime" id="StartTime" type='text' required class="form-control" />
<span class="input-group-addon">
<i class="fa fa-clock-o"></i>
</span>
</div>
<script type="text/javascript">
$(function() {
$('#datetimepicker3').datetimepicker({
format: 'LT'
});
});
</script>
</div>
<div class="form-group col-lg-3">
<label for="StartDate">End Date: </label>
<input type="date" required class="form-control" name="EndDate" id="EndDate" />
</div>
<div class="form-group col-lg-3">
<label for="EndTime" style="margin: 0 0 15px 0;">End Time: </label>
<div class='input-group date' id='datetimepicker4'>
<input name="EndTime" id="EndTime" required type='text' class="form-control" />
<span class="input-group-addon">
<i class="fa fa-clock-o"></i>
</span>
</div>
<script type="text/javascript">
$(function() {
$('#datetimepicker4').datetimepicker({
format: 'LT'
});
});
</script>
</div>
</div>
<div class="row">
<div class="form-group col-lg-3">
<label for="riders_name">Riders Name: </label>
<select class="form-control" style="height: 34px;" required name="riders_name" id="riders_name"></select>
</div>
<div class="form-group col-lg-3">
<label for="horses_name">Horses Name : </label>
<select class="form-control" style="height: 34px;" required name="horses_name" id="horses_name">
<option value="">--Empty--</option>
</select>
</div>
<div class="form-group col-lg-3">
<label for="instructor_name">Instructor Name : </label>
<select class="form-control" style="height: 34px;" required name="instructor_name" id="instructor_name">
<option value="">--Empty--</option>
</select>
</div>
<div class="form-group col-lg-3">
<label for="groom_name">Groom Name : </label>
<select class="form-control" style="height: 34px;" required name="groom_name" id="groom_name">
<option value="">--Empty--</option>
</select>
</div>
</div>
<br>
<div class="row">
<div class="form-group col-lg-9">
<label for="comments">Comments : </label>
<textarea name="comments" id="comments" class="form-control"></textarea>
</div>
<div class="form-group col-lg-3">
<label for="Repeat">Repeat : </label>
<select class="form-control" style="height: 34px;" required name="Repeat" id="Repeat">
<option value="0">none</option>
<option value="1">Daily</option>
<option value="2">Weekly</option>
<option value="3">Monthly</option>
</select>
</div>
</div>
<div class="row">
<div class="form-group col-lg-1">
<button type="submit" class="btn btn-primary" name="submit" id="submit">Submit</button>
</div>
<div class="form-group col-lg-1">
<button type="submit" class="btn btn-danger" name="cancel" id="cancel">Cancel</button>
</div>
<div class="form-group col-lg-5">
</div>
<div class="form-group col-lg-5">
</div>
</div>
</form>
</div>
<script>
$.getJSON("fullcalendar/getriders.php", function(data) {
var select = $('#riders_name'); //combo/select/dropdown list
if (select.prop) {
var options = select.prop('options');
} else {
var options = select.attr('options');
}
$('option', select).remove();
$.each(data, function(key, value) {
options[options.length] = new Option(value['name'], value['id']);
});
});
$.getJSON("fullcalendar/getinstructors.php", function(data) {
var select = $('#instructor_name'); //combo/select/dropdown list
if (select.prop) {
var options = select.prop('options');
} else {
var options = select.attr('options');
}
$('option', select).remove();
$.each(data, function(key, value) {
options[options.length] = new Option(value['name'], value['id']);
});
});
$.getJSON("fullcalendar/getgrooms.php", function(data) {
var select = $('#groom_name'); //combo/select/dropdown list
if (select.prop) {
var options = select.prop('options');
} else {
var options = select.attr('options');
}
$('option', select).remove();
$.each(data, function(key, value) {
options[options.length] = new Option(value['name'], value['id']);
});
});
</script>
I see several empty <select></select> tags in your form. I suspect you are intending text fields there? If so you need to replace <select></select> with <input type="text" />.
Example, this:
<label for="riders_name">Riders Name: </label>
<select class="form-control" style="height: 34px;" required name="riders_name" id="riders_name"></select>
...should be:
<label for="riders_name">Riders Name: </label>
<input class="form-control" type="text" style="height: 34px;" required name="riders_name" id="riders_name" />
Select drop down always higher z-index set by default by browsers. You have two row one underneath other. You should in top row set higher z-index value with position: relative; then I hope it will work as expected.
Add CSS code with following way:
.higher-z-index {
postion: relative; // This line help z-index work relatively
z-index: 999;
}
Your markup will be something like that:
<div class="row higher-z-index">
.....
....
</div>
<div class="row">
.....
....
</div>
Why this approach:
You should keep it mind this is dose not matter how much z-index value applied in .form-group selector it will work for only sibling elements. But in your case it is going behind of next row elements because modern browsers set by default higher z-index in each next sibling elements until we set explicitly. So underneath row getting higher z-index than top row. So it is dose not matter how many higher z-index value are applied inside of top row container, all will go behind of next row container.
Related
I have been trying to make HTML Code to to connect to google Sheet to paste data but my code is still appearing an error even while making it i do not know what is the reason someone can please look into this matter.
The problem is that Form window is not getting open to fill the form for submission of data in google sheets.
I would really appreciate the help.
Here is sheet attached link
https://docs.google.com/spreadsheets/d/1qFNb5NPuJBvgG7u3UxcNcf4h6hu2lkuabP7emLc7pwE/edit?usp=sharing
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<script>
function AddRow()
{
var Invoice = document.getElementById("Invoice").value;
var InvoiceDate = document.getElementById("InvoiceDate").value;
var Code = document.getElementById("Code").value;
var Size = document.getElementById("Size").value;
var ProductName = document.getElementById("ProductName").value;
var Transaction = document.getElementById("Transaction").value;
var StockQty = document.getElementById("StockQty").value;
var MRP = document.getElementById("MRP").value;
if(InvoiceDate != '' && Code != '' && Size != '' && ProductName != '' && Transaction != '' && StockQty != '' && MRP != '')
{
google.script.run.AddRecord(InvoiceDate, Code, Size, ProductName, Transaction, StockQty, MRP);
document.getElementById("Invoice").value = '';
document.getElementById("InvoiceDate").value = '';
document.getElementById("Code").value = '';
document.getElementById("Size").value = '';
document.getElementById("ProductName").value = '';
document.getElementById("Transaction").value = '';
document.getElementById("StockQty").value = '';
document.getElementById("MRP").value = '';
document.getElementById("display_error").innerHTML = "";
}
else
{
document.getElementById("display_error").innerHTML = "Please Enter All Information!";
}
}
</script>
</head>
<body>
<div style="padding: 10px;" >
<form>
<div class="form-row">
<div class="form-group col-md-3">
<label for="Timestamp">Invoice</label>
<input type="text" id="Timestamp" class="form-control" />
</div>
<div class="form-group col-md-3">
<label for="Name">InvoiceDate</label>
<input type="text" id="Name" class="form-control" />
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="Shift">Code</label>
<input type="text" id="Shift" class="form-control" />
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="Product">Size</label>
<input type="text" id="Product" class="form-control" />
</div>
<div class="form-group col-md-3">
<label for="Batch">ProductName</label>
<input type="text" id="Batch" class="form-control" />
</div>
<div class="form-group col-md-3">
<label for="Machine" >Transaction</label>
<input type="text" id="Machine" class="form-control" />
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="MfgExp" >StockQty</label>
<input type="text" id="MfgExp" class="form-control "/>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<label for="Yield" >MRP</label>
<input type="text" id="Yield" class="form-control "/>
</div>
</div>
<div class="form-group col-md-3">
<input type="button" value="Submit" class="btn btn-primary" onclick="AddRow()" />
<div id="display_error" style="color: red" ></div>
</div>
</form>
</div>
</body>
</html>
I believe you are confusing labels with input element ids.
When you write var Invoice = document.getElementById("Invoice").value;, you are telling the script to find the element with id="Invoice" in your HTML.
As you can tell when you press the submit button the console will show the error: "Cannot get value property of null" which means it was not able to find an element with the id supplied to document.getElementById. <-- Read this docs before continuing.
Solution:
Change your HTML <input> elements' id attributes to correspond to the value that you are passing as id parameter to document.getElementById
Example:
From your HTML code I extracted the following lines, please see the comments:
<script>
var Invoice = document.getElementById("Invoice").value; // Here you are saying id="Invoice".
</script>
<div class="form-group col-md-3">
<label for="Timestamp">Invoice</label>
<input type="text" id="Timestamp" class="form-control" /> <!-- Here: id="Timestamp" -->
</div>
So that is why you are getting errors. Map the input id's correctly. But more importantly reading up on HTML and JavaScript would help a lot.
I have a problem with jQuery. I have an html page with a form.
In my form I have a select:
<select class="form-control" id="macro_area" name="macro_area">
<option value="0">Select type</option>
<option value="1">test</option>
<option value="7">Other</option>
</select>
When I select an option, I load a php file with this jQuery function:
$('document').ready(function() {
$('#macro_area').on('change', function() {
request = $.ajax({
type: "POST",
url: "get_bus_act_subcat.php",
data: { id_macro_area: id_macro_area },
dataType: "html"
});
request.done(function(response) {
$(".act_subcat").html (response);
});
});
The procedure works correctly and adds html code (generated from the file get_bus_act_subcat.php) to the page, in a div (<div class="form-group act_subcat">) originally empty.
Code generated and inserted in page is similar to this:
<div class="form-check">
<div class="container">
<div class="row">
<div class="col-sm-3">
<input type="checkbox" class="form-check-input" name="id_sub_cat[]" id="sub_cat_5" value="5">Test1
</div>
<div class="col-sm-3">
<input type="checkbox" class="form-check-input" name="id_sub_cat[]" id="sub_cat_6" value="6">Test2
</div>
<div class="col-sm-3">
<input type="checkbox" class="form-check-input" name="id_sub_cat[]" id="sub_cat_2" value="2">Test3
</div>
......
</div>
</div>
</div>
So the final result is:
<div class="form-group act_subcat"> //this div is present on page when load
<div class="form-check">
<div class="container">
<div class="row">
<div class="col-sm-3">
<input type="checkbox" class="form-check-input" name="id_sub_cat[]" id="sub_cat_5" value="5">Test1
</div>
<div class="col-sm-3">
<input type="checkbox" class="form-check-input" name="id_sub_cat[]" id="sub_cat_6" value="6">Test2
</div>
<div class="col-sm-3">
<input type="checkbox" class="form-check-input" name="id_sub_cat[]" id="sub_cat_2" value="2">Test3
</div>
......
</div>
</div>
</div>
</div>
Now I have my problem... I want to check with jQuery if any of the checkboxes have been checked but standard solution/selector not function.
I think because the checkbox fields have been added later.
Any ideas or suggestions?
Thanks
Maybe the following is helpful to you?
$('.act_subcat').on('change','input',
function(ev){console.log(this.id+" was clicked and is"+(this.checked?"":" not")+" checked");}
)
$('document').ready(function(){
$('#macro_area').on('change', function(){
$(".act_subcat").html(insertHTML(this.value));
});
});
// substitute for AJAX:
function insertHTML(i){return `<div class="form-check">
<div class="container">
<div class="row">
<div class="col-sm-3">
<input type="checkbox" class="form-check-input" name="id_sub_cat[]" id="sub_cat_${i}" value="5">Test${i++}
</div>
<div class="col-sm-3">
<input type="checkbox" class="form-check-input" name="id_sub_cat[]" id="sub_cat_${i}" value="6">Test${i++}
</div>
<div class="col-sm-3">
<input type="checkbox" class="form-check-input" name="id_sub_cat[]" id="sub_cat_${i}" value="2">Test${i}
</div>
</div>
</div>
</div>`;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select class="form-control" id="macro_area" name="macro_area">
<option value="0">Select type</option>
<option value="1">test</option>
<option value="7">Other</option>
</select>
<div class="act_subcat"></div>
I replaced your AJAX part with another HTML-importing function. I demonstrate the event binding with an .on relative to the .act_subcat container. The function inside will fire whenever an input element in this container changes. And this will work for any dynamically added content. Try it out.
One approach you can take is to attach the event listener to the returned content prior to adding it to the page:
$(response).find(':checkbox').on('change', function() {
console.log( `Checkbox with id: ${this.id} was clicked` );
});
//then ... append it ......html( response );
I have an issue where by I need a nicer-looking way to use select option that caters to Countries (240+ countries). I plan to use select2 to enhance the searching experience.
Now, a regular select-option with some values in it will just look like this
<select>
<option value=..></option>
<select>
But in the case of selecting Nationality, there are 240+ countries and suddenly a nice piece of code like this will look terrible.
<div class="form-group">
<label for="alias" class="col-sm-2 control-label">Alias</label>
<div class="col-sm-10">
<input type="text" class="form-control input-sm" id="alias" placeholder="Employee alias">
</div>
</div>
<div class="form-group">
<label for="dob" class="col-sm-2 control-label">DoB</label>
<div class="col-sm-10">
<input type="text" class="form-control input-sm" id="dob" placeholder="Date of birth">
</div>
</div>
<! 240++ lines worth of options->
Any inputs?
You can use JQuery and Array() for this kind of things someway. Just put the countries you want to be shown in var countries which is array. But it will be easier to make .cvs file that has all the country names on the database and call them from it. Anyways this JQuery source might help for your question.
$(document).ready(function(){
var countries = new Array();
/* here you put all the countries you want in array */
countries = ["Korea", "USA", "China", "India", "etc"];
for(i = 0;i < countries.length;i++) {
$("#select2").append("<option value='"+countries[i]+"'>"+countries[i]+"</option>");
}
});
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<title>test</title>
</head>
<div class="form-group">
<label for="alias" class="col-sm-2 control-label">Alias</label>
<div class="col-sm-10">
<input type="text" class="form-control input-sm" id="alias" placeholder="Employee alias">
</div>
</div>
<div class="form-group">
<label for="dob" class="col-sm-2 control-label">DoB</label>
<div class="col-sm-10">
<input type="text" class="form-control input-sm" id="dob" placeholder="Date of birth">
</div>
</div>
<!-- 240++ lines worth of options -->
<div class="form-group">
<label for="select2" class="col-sm-2 control-label">Select Country</label>
<div class="col-sm-10">
<!-- this is where countries enters -->
<select name="" id="select2">
</select>
</div>
</div>
</body>
</html>
So my validation is working the way it should with the exception of the buttons. I want them grayed out with opacity until all is valid and not sure if I have the ng-class set correctly and/or the ng-disabled set correctly or both.
The issue here is more per functionality. I have some fields that show when other fields dropdowns are selected to a particular item. For instance, "Age" is only shown is a particular option is selected whereas with all the other options, it does not show. I show my HTML and then my CSS below.
Yes, is a lengthy form, but hoping you all can help!
My form:
<form class="addClaim" name="claimForm" novalidate ng-submit="saveClaim(claimInfo)" data-ng-model="claimInfo">
<div class="form-group col-md-6 naviaInp">
<label for="beneSelect">Select your benefit</label>
<select class="form-control" name="beneSelect" id="beneSelect" ng-model="benefit" ng-options="item.descr for item in claim" required>
<option value="">Please select a benefit....</option>
</select>
<input type="hidden" ng-model="claimInfo.benefitId" ng-change="{{ claimInfo.benefitId = benefit.id }}"/>
</div>
<div ng-show="claimForm.beneSelect.$dirty && claimForm.beneSelect.$error.required" class="errorContainer">
<p class="claimError"><i class="fa fa-exclamation-circle"></i><span>this is a required field</span></p>
</div>
<div class="form-group col-md-8 naviaInp" ng-show="benefit.askSecIns == true" >
<label for="secInc">Do you have secondary insurance</label>
<div>
<label class="radio-inline"><input type="radio" name="optradioSecIns" data-ng-model="claimInfo.isSecIns" value="true">yes</label>
<label class="radio-inline"><input type="radio" name="optradioSecIns" data-ng-model="claimInfo.isSecIns" value="false">no</label>
</div>
</div>
<div class="checkbox form-group col-md-8 naviaInp" ng-show="benefit.askResidual == true">
<p>If you have a Health Care FSA, any residual amount not covered by the HRA will automatically be entered into the FSA. If you do not wish to have the residual amount entered into your Health Care FSA, please indicate </p>
<label><input type="checkbox" name="residualAmount" data-ng-value="true" ng-model="claimInfo.isNoResId">
<p>No, please do not enter residual amounts into my Health Care FSA</p>
</label>
</div>
<div class="form-group col-md-6 naviaInp" ng-show="benefit.expenseTypes != null">
<label for="beneTypeSelect">Select type of service</label>
<select class="form-control" name="expenseType" id="beneServiceSelect" ng-model="expense" ng-options="item.descr for item in benefit.expenseTypes" required>
<option value="">Please select a service....</option>
</select>
<input type="hidden" ng-model="claimInfo.expenseTypeId" ng-change="{{ claimInfo.expenseTypeId = expense.id }}" />
</div>
<div ng-show="claimForm.expenseType.$dirty && claimForm.expenseType.$error.required" class="errorContainer">
<p class="claimError"><i class="fa fa-exclamation-circle"></i><span>this is a required field</span></p>
</div>
<div class="form-group naviaInp">
<label for="start">Date of Service</label>
<div>
<input type="text" class="form-control" name="startDate" id="start" placeholder="--/--/----" data-ng-model="claimInfo.fromDate" style="width: 200px;" required>
<span style="padding-left: 20px; padding-right: 20px;">To</span>
<input type="text" class="form-control" id="end" placeholder="--/--/---- (optional)" data-ng-model="claimInfo.toDate" style="width: 200px;">
</div>
</div>
<div ng-show="claimForm.startDate.$dirty && claimForm.startDate.$error.required" class="errorContainer">
<p class="claimError"><i class="fa fa-exclamation-circle"></i><span>this is a required field</span></p>
</div>
<div class="form-group col-md-6 naviaInp">
<label for="providerName">Provider Name</label>
<input type="text" name="providerName" class="form-control " id="providerName" ng-maxlength="100" data-ng-model="claimInfo.provider" required>
</div>
<div ng-show="claimForm.providerName.$dirty && claimForm.providerName.$error.required" style="clear: both; margin-top: 8px;">
<p class="claimError" style="color: #ab2328;"><i class="fa fa-exclamation-circle"></i><span style="padding-left: 10px; font-size: 14px; margin-bottom:: 25px;">this is a required field</span></p>
</div>
<div ng-show="claimForm.providerName.$dirty && claimForm.providerName.$error.maxlength" class="errorContainer" style="clear: both; margin-top: 8px;">
<p class="claimError" style="color: #ab2328;"><i class="fa fa-exclamation-circle"></i><span style="padding-left: 10px; font-size: 14px; margin-bottom:: 25px;">must be less than 100 characters</span></p>
</div>
<div class="form-group col-md-6 naviaInp" ng-model="claimInfo.depId" ng-show="benefit.dependents != null">
<label for="beneTypeSelect">Select dependant</label>
<select class="form-control" name="depSelect" id="beneDepSelect" ng-model="dependent" ng-options="item.name for item in benefit.dependents" required>
<option value="">Please select a dependant....</option>
</select>
<input type="hidden" ng-model="claimInfo.depId" ng-change="{{ claimInfo.depId = dependent.id }}" required />
</div>
<div ng-show="claimForm.depSelect.$dirty && claimForm.depSelect.$error.required" class="errorContainer">
<p class="claimError"><i class="fa fa-exclamation-circle"></i><span>this is a required field</span></p>
</div>
<div class="form-group col-md-6 naviaInp" name="forWhom" ng-show="benefit.dependents == null">
<label for="forWhom">For Whom</label>
<input type="text" class="form-control" id="forWhom" ng-maxlength="100" data-ng-model="claimInfo.who" required >
</div>
<div ng-show="claimForm.forWhom.$dirty && claimForm.forWhom.$error.required" class="errorContainer">
<p class="claimError"><i class="fa fa-exclamation-circle"></i><span>this is a required field</span></p>
</div>
<div ng-show="claimForm.forWhom.$dirty && claimForm.forWhom.$error.maxlength" class="errorContainer">
<p class="claimError"><i class="fa fa-exclamation-circle"></i><span>a maximum of 100 characters are allowed</span></p>
</div>
<div class="form-group col-md-4 naviaInp" name="age" ng-show="benefit.benefCode == 'DCFSA'">
<label for="age">Age</label>
<input type="text" class="form-control" id="age" data-ng-model="claimInfo.age" ng-maxlength="50" required>
</div>
<div ng-show="claimForm.age.$dirty && claimForm.age.$error.required" class="errorContainer">
<p class="claimError"><i class="fa fa-exclamation-circle"></i><span>this is a required field</span></p>
</div>
<div ng-show="claimForm.age.$dirty && claimForm.age.$error.maxlength" class="errorContainer">
<p class="claimError"><i class="fa fa-exclamation-circle"></i><span>a maximum of 50 characters are allowed</span></p>
</div>
<div class="form-group col-md-4 naviaInp">
<label for="claimAmount">Amount</label>
<input type="number" name="amount" class="form-control" id="claimAmount" data-ng-model="claimInfo.amount" required ng-pattern="/^\d{1,4}(\.\d{0,2})?$/">
</div>
<div ng-show="claimForm.amount.$dirty && claimForm.amount.$error.required" class="errorContainer">
<p class="claimError"><i class="fa fa-exclamation-circle"></i><span>this is a required field</span></p>
</div>
<div ng-show="claimForm.amount.$dirty && claimForm.amount.$error.pattern" class="errorContainer">
<p class="claimError"><i class="fa fa-exclamation-circle"></i><span>the amount must be between $0 and $10,000</span></p>
</div>
<div class="form-group col-md-8 naviaInp">
<label for="claimComment">Comments</label>
<textarea class="form-control" name="comment" rows="5" id="claimComment" placeholder="optional" ng-maxlength="500" data-ng-model="claimInfo.comments">
</textarea>
</div>
<div ng-show="claimForm.comment.$dirty && claimForm.comment.$error.maxlength" class="errorContainer">
<p class="claimError"><i class="fa fa-exclamation-circle"></i><span>a maximum of 500 characters are allowed</span></p>
</div>
<div class="fileArea col-md-8 naviaInp">
<div>
<p>Drag and drop or upload your documentation. Remember, we cannot review your claim without at least one piece of proper documentation for each claimed expense listed above. Be sure your documentation shows the date of service, type of service, and cost of service.</p>
</div>
<div ngf-drop ngf-select ng-model="files" class="drop-box"
ngf-drag-over-class="'dragover'" ngf-multiple="true" ngf-allow-dir="true"
accept="image/*,application/pdf"
ngf-pattern="'image/*,application/pdf'"><p>Drag and drop your documents here or click to search for your documents and upload</p></div>
<div ngf-no-file-drop><p>File Drag/Drop is not supported for this browser</p></div>
<div>
<p>Files:</p>
</div>
<div>
<ul>
<li ng-repeat="f in files" style="font:smaller">{{f.name}} {{f.$error}} {{f.$errorParam}} <a class="deleteHandle" ng-click="deleteFile($index)">×</a> </li>
</ul>
</div>
</div>
<div style="padding-bottom: 150px; clear: both;">
<div class="checkbox col-md-8">
<label><input type="checkbox" value="" ng-model="checked"><p>By checking this box, you agree to Navia's <a class="naviaLink" data-toggle = "modal" data-target = "#tcModal" >Terms and Conditions</a>.</p></label>
</div>
<div class="form-group" style="clear: both;">
<input type="button" class="naviaBtn naviaBlue" ng-show="editMode == true" ng-click="updateClaim(claimInfo)" value="+ update claim" ng-disabled="claimForm.$invalid" ng-class="{'disabled-class': claimForm.$invalid}">
<input type="button" class="naviaBtn naviaBlue" ng-show="editMode == false" ng-click="saveClaim()" value="+ add another claim" ng-disabled="claimForm.$invalid" ng-class="{'disabled-class': claimForm.$invalid}">
<input type="button" class="naviaBtn naviaBlue" ng-disabled="!checked && claimForm.$invalid" ng-show="editMode == false" ng-class="{'disabled-class': !checked}" ng-click="saveAllClaims()" value="submit claim(s)">
</div>
<div>
<input type="button" class="naviaBtn naviaRed" ng-click="cancel()" value="cancel">
</div>
<div data-ng-hide="message == ''" data-ng-class="(savedSuccessfully) ? 'alert alert-success' : 'alert alert-danger'">
{{message}}
</div>
</div>
</form>
I did abbreviate code as much as I thought I could but still show what I am doing.
And my CSS:
.disabled-class {
background-color: #999999;
opacity: .30;
}
.disabled-class:hover {
background-color: #999999;
opacity: .30;
}
input.ng-invalid.ng-dirty {
border: 1px solid red;
}
.errorContainer {
clear: both;
margin-top: 8px;
}
.claimError {
color: #ab2328;
}
.claimError > span {
padding-left: 10px;
font-size: 14px;
margin-bottom:: 25px;
}
.disabled {
background-color: #999999;
opacity: .30;
}
.disabled:hover {
background-color: #999999;
opacity: .30;
}
What should happen here is that the buttons are grayed and disabled until all required fields have input and that the input is within the parameters set.
The angular form has both validity and invalidity properties.
Actually, all angular form elements do, they are nestable and invalidity bubbles up. If an element is invalid, automatically all the ancestors up to the form itself have $invalid == true.
You can call the form by its name in the $scope and the properties are $valid, respectively $invalid.
Here's the relevant code for your form:
<form name="claimForm">
// your form logic here
<button type="submit" ng-disabled="claimForm.$invalid" />
</form>
UPDATE: If your form doesn't behave the way you want, you should debug it:
divide your form into fieldsets, according to the logic of your form
when each of your fieldset are valid, your form is valid
test each fieldset sepparately and add some divs to display the $valid or $invalid value of each fieldset until you sort it out
I also think you are adding an unnecessary level of complexity to your problem by using inline conditional logic at html level. I'd keep it in the controller, where it's a lot easier to follow and structure.
Whenever something doesn't behave the way you expect it to, console.log(it).
One more thing: once dirty, an element will stay $dirty regardless of being or not disabled, unless you call $setPristine() on it. So you should probably try to avoid using $dirty in yoru logic, it might produce unncecessary confusion.
Most times, value.length and/or $valid are enough to make forms work.
Using bootstrap and can not set an input to hidden. It can be easily set to hidden with JS using
document.getElementById("inputCommentsBrand").style.visibility = "hidden";
but I would like it to be hidden by default.
<div class="form-group">
<label for="inputComments" class="col-sm-2 control-label">Markings</label>
<div class="col-sm-4">
<div><input hidden type="text" class="form-control" id="inputCommentsBrand" name="inputFlags[]" placeholder="Brand and Location: Sbar RH"></div>
<div><input type="text" class="form-control" id="inputCommentsEarTag" name="inputFlags[]" placeholder="Ear Tag Color & #: Green 165"></input></div>
</div>
</div>
Use <body onload="myFunction()"> to hide the field.
Below is the running example.
<script>
function myFunction() {
document.getElementById("inputCommentsBrand").style.visibility = "hidden";
}
</script>
<html>
<body onload="myFunction()">
<div class="form-group">
<label for="inputComments" class="col-sm-2 control-label">Markings</label>
<div class="col-sm-4">
<div><input type="text" class="form-control" id="inputCommentsBrand" name="inputFlags[]" placeholder="Brand and Location: Sbar RH"></div>
<div><input type="text" class="form-control" id="inputCommentsEarTag" name="inputFlags[]" placeholder="Ear Tag Color & #: Green 165"></input></div>
</div>
</div>
</body>
</html>
Instead of visibility:hidden
Use display:none