Code (I'm working with Materialize CSS framework):
<form class="col s12" id="formRequer">
<div class="input-field col s6">
<select id="stdApply" name="stdApply" required>
<option value="" disabled selected>Escolha somente uma das opções</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<label>Selecione o que quer requerer</label>
</div>
</form> <!-- END: form class="col s12" id="formRequer -->
<button class="btn waves-effect waves-light" type="submit" id="btn_submitRequer" form="formRequer">Enviar
<i class="material-icons right">send</i>
</button>
I copied the code excluding CSS and paste it on w3school and it worked fine!
Is it possible that HTMLService evalute() process exclude the required attribute from tag or exclude the value="" attribute from the first option (this is vital for HTML5 select tag works with required attribute)?
Any help?
Try this:
HTML:
<html>
<head></head>
<body>
<form>
<select id="stdApply" name="stdApply">
<option value="" selected>Escolha somente uma das opções</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<label>Selecione o que quer requerer</label>
<br /><input type="button" value="Enviar" onClick="processForm(this.parentNode);" />
</form>
<script>
function processForm(obj) {
if(obj.stdApply.value!='') {
google.script.run.processForm(obj);
}else{
document.getElementById('stdApply').focus();
}
}
</script>
</body>
</html>
Google Script:
function processForm(obj) {
Browser.msgBox(obj.stdApply);
}
function showMyDialog() {
SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutputFromFile('ah3'), 'Test');
}
I am making a dynamic form with multiple fields in bootstrap and when I add a new inline form, it is not aligned with the previous one. I appreciate if someone can help me with that.
image of the form
html:
<!-- start of the column with properties(form-control)-->
<div class="col-lg-8" id="property-col">
<div class="container">
<form class="form">
<div class="row">
<h3>Properties</h3>
<br>
</div>
<div class="row">
<div class="form-group">
<fieldset class="form-inline">
<label class="control-label">Image Size:</label>
<select class="form-control" id="image-size-selector">
<option value="128">128×128</option>
<option value="256">256×256</option>
<option value="512">512×512</option>
<option value="1024">1024×1024</option>
</select>
</fieldset>
</div>
</div>
<div class="row" id="dynamic_form">
<div class="form-group form-horizontal">
<label>Primitives</label>
<div class="container">
<div class="form-inline" id="primitive_fields">
<select class="input-small form-control" id="primitive-selector" name="PrimitiveChoose[]">
<option value=" " disabled selected>primitive</option>
<option value="sphere">sphere</option>
<option value="triangle">triangle</option>
</select>
<input type="number" class="input-small form-control" id="diameter" name="Diameter[]" step="any" placeholder="diameter(D)">
<input type="text" class="input-small form-control" id="sphere-position" name="SpherePosition[]" placeholder="(x, y, z)">
<select class="input-small form-control" id="circle-color-selector" name="CircColorSelect[]" >
<option value=" " disabled selected>color</option>
<option value="red">red</option>
<option value="blue">blue</option>
<option value="green">green</option>
<option value="yellow">yellow</option>
</select>
<button type="button" class="btn btn-success btn-add" id="add_more"> <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
</div>
</div>
</div>
</div>
css:
.form-inline .input-mini
{
width: 70px;
font-weight: bold;
}
.form-inline .input-small
{
width: 120px;
font-weight: bold;
}
#primitive-form > *
{
margin: 2px 2px;
}
Hmmm maybe you need to create a codepen.
It seems align if not created dynamically.
http://codepen.io/seiran/pen/LWwWgX
Try to post your script.
//code is the same -- dont mind this
I think you are asking this type of format here i executed with the single input so you can add your own new things.
The fieldset is closed on the first form itself just cut the fieldset there with the belowed two div and paste at the end.
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script language="javascript">
$(document).ready(function(){
var next = 1;
$(".add-more").click(function(e){
e.preventDefault();
var addto = "#field" + next;
var addRemove = "#field" + (next);
next = next + 1;
var newIn = '<input autocomplete="off" class="input form-control" id="field' + next + '" name="field' + next + '" type="text">';
var newInput = $(newIn);
var removeBtn = '<button id="remove' + (next - 1) + '" class="btn btn-danger remove-me" >-</button></div><div id="field">';
var removeButton = $(removeBtn);
$(addto).before(newInput);
$(addRemove).before(removeButton);
$('.remove-me').click(function(e){
e.preventDefault();
var fieldNum = this.id.charAt(this.id.length-1);
var fieldID = "#field" + fieldNum;
$(this).remove();
$(fieldID).remove();
});
});
});
</script>
</head>
<body>
<div class="container">
<div class="row">
<input type="hidden" name="count" value="1" />
<div class="controls" id="profs">
<form class="input-append">
<div id="field"><input autocomplete="off" class="input" id="field1" name="prof1" type="text" placeholder="Type something" data-items="8"/><button id="b1" class="btn add-more" type="button">+</button></div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
I have implemented bootstrap form validation in my angular2 application and some of the form elements are not getting validated even after using the bootstrap form validation directive properly. When I tried inspecting the code, I found the "has-error" class is not appearing in the form fields.
Here is my form code:
<form id="emailForm"
#emailForm= "ngForm"
novalidate="novalidate"
[saBootstrapValidator]="validatorOptions">
<!-- widget content -->
<div class="widget-body">
<!--template Name -->
<fieldset>
<div class="form-group">
<div class="row">
<section class="col-sm-12 col-md-10">
<strong class="control-label">Name</strong><label class="required"></label>
<input class="form-control"
placeholder="Enter template name"
type="text"
value="{{message.name}}"
name="templateName" [(ngModel)]="composeModel.Name">
</section>
<section class="col-sm-12 col-md-2">
<label for="select2-multiple">
<strong>Category</strong></label>
<select
style="width:100%"
class="form-control select2"
name="category">
<option *ngFor = "let category of templateCategories" value="{{category.Id}}">{{category.Name}}</option>
</select>
</section>
</div>
</div>
</fieldset>
<!--Description -->
<fieldset>
<div class="form-group">
<div class="row">
<section class="col-sm-12 col-md-12 ">
<strong>Description</strong>
<textarea class="form-control" name="review" rows="2" placeholder="Enter a brief summary that decribes the puropose of this template " [(ngModel)]="composeModel.Description"></textarea>
</section>
</div>
</div>
</fieldset>
<!-- To -->
<fieldset>
<div class="form-group">
<div class="row">
<section class="col-md-12">
<strong class="control-label">To</strong><label class="required"></label>
<popover-content #multSelectContent>
<span style="color: #3276B1">Hold ctrl-key to select multiple emails<br /> Start typing to search for email</span>
</popover-content>
<a (click)="(null)"
class="fa fa-question-circle"
popoverPlacement="top"
[popoverOnHover]="true"
data-html="true"
popoverTitle="Multiple Selection"
[popover]="multSelectContent"></a>
<div class="boxed">
<select
multiple select2 style="width:100%"
data-select-search="true"
class="form-control select2-multiple"
name="emailTo">
<optgroup label="Responsible Parties">
<option value="1"> sunny.orlaf#smartadmin.com</option>
<option value="2"> rachael.hawi#smartadmin.com</option>
<option value="3"> michael.safiel#smartadmin.com</option>
</optgroup>
<optgroup label="Evaluator">
<option value="alex.jones#infowars.com"> alex.jones#infowars.com</option>
<option value="oruf.matalla#gmail.com"> oruf.matalla#gmail.com</option>
<option value="hr#smartadmin.com"> hr#smartadmin.com</option>
<option value="IT#smartadmin.com"> IT#smartadmin.com</option>
</optgroup>
<optgroup label="Informed Parties">
<option value="alex.jones#infowars.com"> alex1.jones#infowars.com</option>
<option value="oruf.matalla#gmail.com"> oruf1.matalla#gmail.com</option>
<option value="hr#smartadmin.com"> hr1#smartadmin.com</option>
<option value="IT#smartadmin.com"> IT1#smartadmin.com</option>
</optgroup>
</select>
</div>
</section>
</div>
</div>
</fieldset>
<!-- CC -->
<fieldset>
<div class="form-group">
<div class="row">
<section class="col-sm-12 col-md-6">
<label><strong>CC</strong></label>
<popover-content #multSelectContent1>
<span style="color: #3276B1">Hold ctrl-key to select multiple emails<br /> Start typing to search for email</span>
</popover-content>
<a (click)="(null)" class="fa fa-question-circle" popoverPlacement="top" [popoverOnHover]="true" data-html="true" popoverTitle="Multiple Selection" [popover]="multSelectContent1"></a>
<div class="boxed">
<select multiple select2 style="width:100%" data-select-search="true" class="select2">
<optgroup label="Responsible Parties">
<option value="sunny.orlaf#smartadmin.com">sunny.orlaf#smartadmin.com</option>
<option value="rachael.hawi#smartadmin.com">rachael.hawi#smartadmin.com</option>
<option value="michael.safiel#smartadmin.com">michael.safiel#smartadmin.com</option>
</optgroup>
<optgroup label="Evaluator">
<option value="alex.jones#infowars.com">alex.jones#infowars.com</option>
<option value="oruf.matalla#gmail.com">oruf.matalla#gmail.com</option>
<option value="hr#smartadmin.com">hr#smartadmin.com</option>
<option value="IT#smartadmin.com">IT#smartadmin.com</option>
</optgroup>
<optgroup label="Informed Parties">
<option value="alex.jones#infowars.com">alex1.jones#infowars.com</option>
<option value="oruf.matalla#gmail.com">oruf1.matalla#gmail.com</option>
<option value="hr#smartadmin.com">hr1#smartadmin.com</option>
<option value="IT#smartadmin.com">IT1#smartadmin.com</option>
</optgroup>
</select>
</div>
</section>
<!-- BCC -->
<section class="col-sm-12 col-md-6">
<label><strong>BCC</strong></label>
<popover-content #multSelectContent1>
<span style="color: #3276B1">Hold ctrl-key to select multiple emails<br /> Start typing to search for email</span>
</popover-content>
<a (click)="(null)" class="fa fa-question-circle" popoverPlacement="top" [popoverOnHover]="true" data-html="true" popoverTitle="Multiple Selection" [popover]="multSelectContent1"></a>
<div class="boxed">
<select multiple select2 style="width:100%" data-select-search="true" class="select2">
<optgroup label="Responsible Parties">
<option value="sunny.orlaf#smartadmin.com">sunny.orlaf#smartadmin.com</option>
<option value="rachael.hawi#smartadmin.com">rachael.hawi#smartadmin.com</option>
<option value="michael.safiel#smartadmin.com">michael.safiel#smartadmin.com</option>
</optgroup>
<optgroup label="Evaluator">
<option value="alex.jones#infowars.com">alex.jones#infowars.com</option>
<option value="oruf.matalla#gmail.com">oruf.matalla#gmail.com</option>
<option value="hr#smartadmin.com">hr#smartadmin.com</option>
<option value="IT#smartadmin.com">IT#smartadmin.com</option>
</optgroup>
<optgroup label="Informed Parties">
<option value="alex.jones#infowars.com">alex1.jones#infowars.com</option>
<option value="oruf.matalla#gmail.com">oruf1.matalla#gmail.com</option>
<option value="hr#smartadmin.com">hr1#smartadmin.com</option>
<option value="IT#smartadmin.com">IT1#smartadmin.com</option>
</optgroup>
</select>
</div>
</section>
</div>
</div>
</fieldset>
<!--Subject -->
<fieldset>
<div class="form-group">
<div class="row">
<section class="col-md-12 ">
<label><strong>Subject</strong></label>
<popover-content #multSelectContent>
<span style="color: #3276B1">Hold ctrl-key to select multiple emails<br /> Start typing to search for email</span>
</popover-content>
<a (click)="(null)"
class="fa fa-question-circle"
popoverPlacement="top"
[popoverOnHover]="true"
data-html="true"
popoverTitle="Multiple Selection"
[popover]="multSelectContent"></a>
<div class="boxed">
<select
multiple select2 style="width:100%"
data-select-search="true"
class="form-control select2-multiple"
name="emailTo"
placeholder = "Email Subject">
<optgroup label="Evaluation type title">
</optgroup>
<optgroup label="Topic">
<option value="topic1">topic1</option>
<option value="topic2">topic2</option>
</optgroup>
<optgroup label="Question">
<option value="question1">Question1</option>
<option value="question2">Question2</option>
</optgroup>
<optgroup label="Response">
<option value="response1">response1</option>
<option value="response2">response2</option>
</optgroup>
<optgroup label="Value">
<option value="value1">value1</option>
<option value="value2">value2</option>
</optgroup>
<optgroup label="Today's Date'">
<option value="4.5.2017">4.5.2017</option>
</optgroup>
</select>
</div>
<!--<input class="form-control" placeholder="Email Subject" type="text" value="{{message.subject}}">-->
</section>
</div>
</div>
</fieldset>
<!--Message -->
<fieldset>
<div class="form-group">
<div class="row">
<section class="col-md-12 ">
<strong>Message</strong><label class="control-label required"></label>
<div class="summernote form-control" name="messageBody" [summernote]="{height: 120}"></div>
</section>
</div>
</div>
</fieldset>
<!--Action buttons -->
<fieldset>
<div class="smart-form pull-right">
<section class="col-md-12 p ">
<div class="btn-group">
<button class="btn btn-sm btn-primary" type="button"><i class="fa fa-times"></i> Cancel </button>
</div>
<div class="btn-group">
<button class="btn btn-sm btn-success" type="submit" [disabled]="!emailForm.invalid" (click)="onSubmit()"><i class="fa fa-save"></i> Save </button>
</div>
</section>
</div>
</fieldset>
</div>
<!-- end widget content -->
</form>
This is how my form appears :
Here is my component.ts code:
import { Component, OnInit } from '#angular/core';
import { ActivatedRoute, Router } from '#angular/router';
import { OutlookService, Message } from '../shared';
import { EmailComposeService } from '../compose/compose.service';
import { EmailComposeModal } from '../../data-model/email-compose';
declare var $: any;
#Component({
selector: 'sa-compose',
templateUrl: 'compose.component.html',
})
export class ComposeComponent implements OnInit {
public $: any;
validatorOptions = {
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
templateName: {
validators: {
notEmpty: {
message: 'The template name is required and cannot be empty'
}
}
},
emailTo: {
validators: {
notEmpty: {
message: 'The sender email is required and cannot be empty'
}
}
},
messageBody: {
validators: {
callback: {
message: 'The content is required and cannot be empty',
callback: function (value, validator, $field) {
var code = $('[name="messageBody"]').summernote('code');
// <p><br></p> is code generated by Summernote for empty content
return (code !== '' && code !== '<p><br></p>');
}
}
}
}
}
};
public templateName: String = '';
public message: Message;
public carbonCopy: boolean = false;
public blindCarbonCopy: boolean = false;
public attachments: boolean = false;
public sending: boolean = false;
templateCategories: any;
constructor(private route: ActivatedRoute,
private router: Router,
private service: OutlookService, private composeservice: EmailComposeService) {
}
ngOnInit() {
this.message = new Message({})
this.composeservice.getTempateCategory(1, JSON.parse(localStorage.getItem('currentUser')).access_token).subscribe(data => {
this.templateCategories = data;
this.composeModel.CategoryId = data[0].Id;
});
}
isUpdate: boolean = false;
isDelete: boolean = false;
isCreateTemplate: boolean = false;
submitted = false;
composeModel = new ComposeClass();
onSubmit() {
//this.uploadImage();
if (this.isUpdate) {
let composePutData: EmailComposeModal = {
Id: +this.composeModel.Id,
IndustryId: +this.composeModel.IndustryId,
CategoryId: +this.composeModel.CategoryId,
Name: this.composeModel.Name,
Content: this.composeModel.Content,
Description: this.composeModel.Description,
Status: this.composeModel.Status,
CreatedBy: this.composeModel.CreatedBy,
CreateTimestamp: this.composeModel.CreateTimestamp,
ModifiedBy: localStorage.getItem('selectedRolesID'),
ModifiedTimestamp: new Date(),
DataStateFlag: this.composeModel.DataStateFlag
}
if (this.isDelete) {
this.composeservice.updateTemplate(composePutData, JSON.parse(localStorage.getItem('currentUser')).access_token).subscribe(res => {
if (res.status === 200) {
this.isUpdate = false;
this.isDelete = false;
this.composeModel = new ComposeClass();
this.isCreateTemplate = false;
$('.divMessageBox').hide();
}
});
} else {
this.composeservice.updateTemplate(composePutData, JSON.parse(localStorage.getItem('currentUser')).access_token).subscribe(res => {
if (res.status === 200) {
this.isUpdate = false;
this.composeModel = new ComposeClass();
this.isCreateTemplate = false;
$('.divMessageBox').hide();
}
});
}
} else {
var code = $('[name="messageBody"]').summernote('code');
let postdata: EmailComposeModal = {
IndustryId: 1,
CategoryId: +this.composeModel.CategoryId,
Name: this.composeModel.Name,
Content: code,
Description: this.composeModel.Description,
Status: "Active",
CreatedBy: localStorage.getItem('selectedRolesID'),
CreateTimestamp: new Date(),
DataStateFlag: "I",
"ModifiedBy": null,
"ModifiedTimestamp": null
}
this.submitted = true;
this.composeservice.createTemplate(postdata, JSON.parse(localStorage.getItem('currentUser')).access_token).subscribe(res => {
if (res.status === 200) {
this.composeModel = new ComposeClass();
this.isCreateTemplate = true;
$('.nav-tabs a[href="#a1"]').tab('show');
$('[name="messageBody"]').summernote('reset');
}
})
}
}
}
export class ComposeClass {
constructor(
public Id?: number,
public IndustryId?: number,
public CategoryId?: number,
public Name?: string,
public Content?: string,
public Description?: string,
public Status?: string,
public CreatedBy?: string,
public CreateTimestamp?: Date,
public ModifiedBy?: string,
public ModifiedTimestamp?: Date,
public DataStateFlag?: string
) {
}
}
The first input element is getting getting validated but the select fields and summernote fields are not getting validated.
I have finally resolved it.
The select2 validation would work simply if the excluded: [':disabled'] is added to the validatorOptions. It checks for null value.
Regarding the summernote, adding the following code to onInit() solved the issue :
$(".summernote")
.on('summernote.change', function(customEvent, contents, $editable) {
// Revalidate the content when its value is changed by Summernote
$('#emailForm').bootstrapValidator('revalidateField', 'content');
Hope this helps!
This is my code:
<script type="text/javascript">
function goToNewPage ()
{
var url = document.getElementById('list').value;
if(url != 'none') {
window.location = url;
}
}
</script>
</head>
<body>
<header>
<nav>
<a href="gems.html">
<img src="gems-logo.png" alt="Gems Logo" height="120" width="150">
</a>
<ul>
<li>Home</li>
<select name="list" id="list" accesskey="target">
<option value='none' selected></option>
<option value="available-services.html">Available Services</option>
<option value="construction.html">Construction Cleaning</option>
<option value="maintenance.html">Maintenance Cleaning</option>
<option value="residential.html">Residential Cleaning</option>
<option value="office.html">Office Cleaning</option>
</select>
<input type=button value="Go" onclick="goToNewPage()" />
<select name="drop" id="drop" accesskey="target">
<option value='none' selected></option>
<option value="about-gems.html">About Gems</option>
<option value="spring-fall.html">Spring/Fall Information</option>
<option value="application.html">Apply</option>
<option value="pricing.html">Pricing</option>
<option value="contact-us.html">Contact Us</option>
</select>
<input type=button value="Go" onclick="goToNewPage()" />
</ul>
</nav>
</header>
The two button types are yellow in notepad++ and the first drop down works but the second one is allowing me to select an option but the button isn't letting me go to the page that I select. I've tried to rename the button and to rename the button inside the code for example button1 but all that gave me was a type of search bar.
Right, I have sorted it for you but you are trying to do something you cannot do.
As I said, your dropdowns cannot have the same ID as any other element in the DOM or JS cannot find it.
Having two buttons call the same function expecting them to do different things is mental.
I have provided a modified version of your code below that works.
<html>
<head>
<title></title>
<script type="text/javascript">
var goToNewPage1 = function()
{
var url = document.getElementById('list1').value;
if(url != 'none') {
window.location = url;
}
}
var goToNewPage2 = function()
{
var url = document.getElementById('list2').value;
if(url != 'none') {
window.location = url;
}
}
</script>
</head>
<body>
<header>
<nav>
<a href="gems.html">
<img src="gems-logo.png" alt="Gems Logo" height="120" width="150">
</a>
<ul>
<li>Home</li>
</ul>
<select name="list1" id="list1" accesskey="target">
<option value="none" selected=""></option>
<option value="available-services.html">Available Services</option>
<option value="construction.html">Construction Cleaning</option>
<option value="maintenance.html">Maintenance Cleaning</option>
<option value="residential.html">Residential Cleaning</option>
<option value="office.html">Office Cleaning</option>
</select>
<input type="button" value="Go" onclick="goToNewPage()">
<select name="list2" id="list2" accesskey="target">
<option value="none" selected=""></option>
<option value="about-gems.html">About Gems</option>
<option value="spring-fall.html">Spring/Fall Information</option>
<option value="application.html">Apply</option>
<option value="pricing.html">Pricing</option>
<option value="contact-us.html">Contact Us</option>
</select>
<input type="button" value="Go" onclick="goToNewPage()">
</nav>
</header>
</body>
</html>
I have a form with two fields, a drop-down list and a text box. Both drop-down and text box are mandatory but with one exception that if user selects "Other" the text-box will not be mandatory and will not show asterisk.
Form:
<form method="post" id="configForm" action="">
<div class="field">
<label class="required" for="type"><em>*</em>Type</label>
<div class="input-box">
<select name="type" class="required-entry">
<option value=""></option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="Other">Other</option>
</select>
</div>
</div>
<div class="field">
<label class="required" for="price"><em>*</em>Price</label>
<div class="input-box">
<input type="text" value="" name="price" class="required-entry">
</div>
</div>
</form>
Script:
<script type="text/javascript">
//< ![C
var Form= new VarienForm('configForm', true);
//]]>
</script>
Its feels awkward while answering my own question but as I solve it myself so posting because it may help someone else.
<script type="text/javascript">
//< ![C
Validation.add('conditional-required', 'This is a required field.', function(v) {
var type = $('type').getValue();
if(type == 'Other')
{
return ( (v != "none") && (v != null) && (v.length != 0));
}
else
{
return true;
}
});
//]]>
</script>
Add id type to dropdown list
<select name="type" class="required-entry" id="type">
Add class conditional-required to text field
<input type="text" value="" name="price" class="conditional-required">
Fairly Simple!