Why aren't input fields showing in format (xxx) xxx-xxxx? - html

I am trying to create an html view that shows three form fields that together collect a United States format phone number in the format (xxx) xxx-xxxx .
How can I write the css to make this happen in an app that uses css3, bootstrap, and html5 along with AngularJS?
My current attempt gets the three input field sizes correctly, but completely messes up the placement of the parens ( and ) and also messes up the placement of the dash -. The parens and dashes are placed almost all over the screen, in that they are almost in different rows, with little or no correlation to the placement of the input fields. What specific changes need to be made to the code below in order to print out the input fields in the format (xxx) xxx-xxx, given css3, html5, bootstrap, and AngularJS?
<div class="row">
<div class="col-sm-1">
(<input class="form-control" type="text" id="phonenum1" name="phonenum1" maxlength="3" size="3" ng-model="auth.resultphone.phonenum1" ng-pattern="auth.onlyNumbers" required />)
</div>
<div class="col-sm-1">
<input class="form-control" type="text" id="phonenum2" name="phonenum2" maxlength="3" size="3" ng-model="auth.resultphone.phonenum2" ng-pattern="auth.onlyNumbers" required />-
</div>
<div class="col-sm-1">
<input class="form-control" type="text" id="phonenum3" name="phonenum3" maxlength="4" size="4" ng-model="auth.resultphone.phonenum3" ng-pattern="auth.onlyNumbers" required />
</div>
</div>
Here is a print screen of what the above code is currently printing in the view:
By contrast, the correct output would put all three fields on the same line within the proper punctuation in the pattern (phonenum1) phonenum2-phonenum3
ONGOING EFFORTS:
Also, if I take #Pauli_D's advice and deviate from the OP by using the RegEx \d{3}[\-]\d{3}[\-]\d{4}, the AngularJS form validation is only partially effective. For example, typing ANYTHING into the phonenum1 input in the code below results in the view displaying the Please enter a phone number in the format 111-222-3333 warning, but the warning DOES NOT GO AWAY when you type in a number in the format 111-222-3333. Here is the code in the view for trying #Paulie_D's suggestion:
<form name="confirmForm" ng-submit="auth.confForm(confirmForm.$valid)" novalidate>
<div class="form-group">
<div class="row">
<label for="auth.resultphone.phonenum1">Cell Phone number:</label>
</div>
<div class="row">
<div class="col-sm-3">
<input class="form-control" type="text" id="phonenum1" name="phonenum1" maxlength="12" size="12" ng-model="auth.resultphone.phonenum1" ng-pattern="auth.usPhone" required />
</div>
</div>
<div class="row">
<p ng-show="confirmForm.phonenum1.$error.required && !confirmForm.phonenum1.$pristine" class="help-block">Area code of cell phone number is required.</p>
<p ng-show="!confirmForm.phonenum1.$valid && !confirmForm.phonenum1.$pristine" class="help-block">Phone number must be in the format 111-222-3333.</p>
<button type="submit" class="btn btn-primary" ng-disabled="confirmForm.$invalid" >Submit</button>
</div>
</div>
</form>
And here is the variable declaration in the service auth.js:
this.usPhone = "\d{3}[\-]\d{3}[\-]\d{4}";
The revised AngularJS code with #PaulieD gives the following print screen. Note that the Submit button is still shaded, so that the form cannot yet be submitted:
So what other changes need to be made?

As for the css alignment issue...
.col-sm-1 {
padding-right: 0;
}
input[size='3'] {
width: 75%;
min-width: 75%;
padding: 0;
display: inline;
}
http://codepen.io/anon/pen/adPrey

Related

HTML Date Input doesn't respect width in iOS 16

I've noticed on the most recent iOS update (iOS 16), all browsers display date inputs with no regard for normal width or height constraints. The code below is used to generate the first two inputs in my form. On previous iOS versions, the Date field would display full width on its own line (in the same way as the Pilot in Command field. However, after the update, it now displays inline and only as wide/tall as the value requires.
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="control-label" id="labelDate">Date: <span style="color: red;">*</span></label>
<input type="date" class="form-control" id="flightDate" value=<?php echo $preloadDate; ?>>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label" id="labelPIC">Pilot in Command: <span style="color: red;">*</span></label>
<input type="text" class="form-control" id="flightPIC" placeholder="Self">
</div>
</div>
On any other operating system, this produces the expected result, however on iOS 16, it produces this:
If I change the type of input to text, it displays normally.
I know that I can set a min-width: 95% on the date input to force it's width, but I was wondering if anyone has a more elegant solution rather than a work around like this.

input element isn't working for the pattern I'm trying to use

On my html page I have:
......
<div class="col-md-3">
<input class="form-control" [(ngModel)]="manufacturer.name" [value]="manufacturer.name" maxlength="30" name="name" id="name" #name="ngModel" pattern="[\x20-\x7E]" required />
</div>
<div class="col-md-6">
<validation-message [control]="name" [message]="'Manufacturer Name must be an alphanumeric value of no more than 30 characters'"></validation-message>
</div>
......
Where I'm trying to restrict input to Ascii 32 to 126 inclusive. However, my Pattern doesn't seem to work. I cannot see what is wrong with it. Basically my validation message stays constantly on screen. How should I write my pattern?

Using pattern and required attribute of input field html at the same time

How can I both validate the pattern of an input field while use required attribute in an html form. I want to make 2 different warning message for each attribute.
<div class="form-group">
<label class="col-md-4 control-label">E-Mail</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
<input name="email" placeholder="Địa chỉ E-Mail" class="form-control" type="text" required
pattern=" /^[a-z0-9._%+-]+#[a-z0-9.-]+\.[a-z]{2,4}$/"
oninvalid="this.setCustomValidity('Vui lòng nhập địa chỉ email')"
oninput="setCustomValidity('')"/>
</div>
</div>
</div>
And anyone have a working regex to check valid email? I found that regex on the Internet but it does not work correctly
Keep it simple :o) Unless you really need to go use the Constraint Validation API, as you are currently doing, I would go with regular Form Validation which has pretty good browser support.
Basically when you apply the required attribute on input elements they will be matched against a few conditions. One is the field cannot be left blank. A second is an optional pattern. In your case, you can specify type="email" and the browser will match the input for a valid email address. As far as I can read your request, the following should cover your needs:
<form action="">
<input type="email" required>
<input type="submit">
</form>
The risk of defining a custom pattern using regex is that you might end up testing for a faulty pattern. In your case, testing for example#example.cancerresearch would fail even if it's a valid email address.

How can I append undeletable value in input form?

I'm trying to do something exactly like this sign up form here. They have appended their domain name as undeletable value to allow user to create a sub domain folder. I want to do the same with following input:
<input type="text" class="form-control inputlogin" name="subdomain_name" placeholder="Sub Domain" required="" value=""/>
I found a technique here but I'm not looking to append a prefix. The value must be after like in the example.
It is just a styling trick. input are either completely editable or disabled (not editable at all). There is no way to get around this.
What is done in the form you linked to is a trick where the "frozen" text is placed upon the input field so it looks as if it is a part of the actual input tag, but it is not.
Se my simple jsfiddle illustration. Look at how the styling can be used to create the illusion you want.
Here is an example using Bootstrap 3:
Bootstrap 3 Sub-domain input
<div class="container">
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control" placeholder="Your sub-domaion here">
<span class="input-group-addon" title="Type of Question">.our-domain.com</span>
</div>
</div>
</div>

HTML5 - unwanted <form> autofocus on mobile browsers

My signup page has two forms; when you go to the page on a mobile browser (confirmed on Android and iOS), it autofocuses on the first input element in the second form and opens the keyboard, jumping past the first form.
All I want is to stop the autofocus entirely because it skips past some pre-signup instructions. (Though it would also be good to understand why/how this happens, and why it chooses the second form to focus on!)
Neither form has the autofocus attribute set
I've tried adding an id="top" and linking to /signup#top - no difference
I have $(window).scrollTop(0) running after the page is rendered (for an unrelated reason) - no difference
I'm using Meteor / Blaze with Semantic UI
The first form is my own, the second form is the userAccounts package signup form
<div class="ui segment">
<p>Information that is skipped past</p>
<form class="ui form" id="welcomeFormEmail">
<input type="email" name="preLaunchEmail" placeholder="Your email address">
<button type="submit">Submit</button>
</form>
<div class="at-pwd-form">
<form id="at-pwd-form" action="#" method="POST" class="ui large form">
<div class="ui stacked segment">
<div class="at-input required field">
<div class="ui fluid input icon">
<input type="email" id="at-field-email" name="at-field-email" placeholder="Email" autocapitalize="none" autocorrect="off">
</div>
</div>
<!-- Various other fields -->
<!-- Various other fields -->
<!-- Various other fields -->
<input type="submit" class="at-btn ui fluid large primary button" id="at-btn" value="Register">
</div>
</form>
</div>
</div>
Any ideas why this is happening and what to do to stop it?
You can use blur
if you have just one text input you can get it using getElementById and set it to blur
document.getElementById("myAnchor").blur();
but if you have multiple text inputs this loop gets every input on your page and disable focus on all of them
var elelist = document.getElementsByTagName("input"); for(var i = 0; i < elelist.length; i++){
elelist[i].addEventListener("focus", function(){
this.blur();
}); }