form input with email keyboard but no validation - forms

I want to build a form (in bootstrap) that has an email or telephone number input field.
In mobile I want that field to open the "email keyboard" and I want it to don't validate if the value is an email.
This form also has some text inputs that I want them to be required.
What is the simple way for this to be achieved?

If I understood your question correctly, you want to validate your form's inputs but DO NOT want to validate teh email input in the same form....
use something like this:
jQuery:
$(document).on('click', ".button", function(){
var name = $(".name").val();
var lastname = $(".lastname").val();
var email = $(".email").val();
if(name == "" || lastname == "" ){
alert('Please fill in all the details')
}else{
///////submit your form here... you can even use AJAX to submit yuour form////
}
});
HTML:
<form action="" method="post">
<input type="text" class="name">
<input type="text" class="lastname">
<input type="email" class="email">
</form>
YOU CAN USE ANY JQUERY LIB.
EDIT:
If you are using html5, the <input type="email" will automatically open the 'keypad email' on your device.
A working FIDDLE:
https://jsfiddle.net/2v7ybe9h/2/
Based on the link you provided in the comments below, this is what it says:
They also provided an example in the same page...
As you can already see, the email input in that page has a 'required' attribute and the pattern attribute.
If you simply remove those attributes, there wont be any "Verification" anymore.
Example here:
https://jsfiddle.net/2v7ybe9h/3/
You can also use the novalidate attribute on your form and simply validate your form using jQuery same as what i have provided you in the first fiddle.
Example:
https://jsfiddle.net/2v7ybe9h/4/

The modern answer (as of 2020) is to use inputmode:
<input type="text" inputmode="email">
<input type="text" inputmode="tel">
See MDN for more

Related

MapBox Autofill Full Address

I am trying to use MapBox Autofill feature to get a full address in an address input field, but I don't see an autocomplete tag that includes full addresses.
I tried to use multiple autocomplete tags to get street addresses, cities, states, etc. without showing them (by using type="hidden"), but then values from the hidden fields don't get submitted along with with the main input field (address):
<form action="/results" method="post">
<input name="address" placeholder="Enter your address" type="text" autocomplete="street-address" />
<input name="city" placeholder="City" autocomplete="address-level2" type="text" disabled="true" />
<p>
<center><button type="submit" class="button btn-send disabled">Search</button></center>
</p>
</form>
Can someone help me understand how I can submit full address through the form without showing secondary input fields?
One solution is to use the retrieve event from mapbox-search, which returns an AutofillRetrieveResponse (promise) from which you can extract the full address.
In the following example I'm getting the full address and setting it as the value of the input field, but you could change this according to your needs.
const autofill = mapboxsearch.autofill({
accessToken: YOUR_MAPBOX_TOKEN,
});
autofill.addEventListener('retrieve', async (event) => {
const fullAddress = event.detail.features[0].properties.full_address;
this.inputTarget.value = await fullAddress;
});

How can I submit a AngularJS model the old-fashioned way?

In my Angular app I'm having a form bound to a model. The form does not have fields for all model properties.
When the user hits the submit button I want to post the form the traditional way, not as AJAX request (I have to deal with an already existing server side script).
That basically works if I add a action to the form. But it obviously only submits the form with its present fields as it is, not the whole model just like it's done when using the $http service.
And additionally it does not create name attributes.
How could I submit the form the old-school way with the full model data? Do I have to create the missing form fields on my own or is there a way to let Angular do that for me?
<script>
angular.module('foobar', []).controller('ContentCtrl', ['$scope', function($scope) {
$scope.content = {
'title': 'Foo',
'subtitle': 'Bar',
'text': 'desc' // this field is missing in the form itself and therefore is not submitted
};
}]);
</script>
<form action="http://postcatcher.in/catchers/521c6510429f840200000169" method="post" ng-controller="ContentCtrl">
<input type="text" name="est" ng-model="content.title" value="asdf">
<input type="text" ng-model="content.subtitle">
<button>submit</button>
see post result
</form>
Here's a plunker: http://plnkr.co/edit/5XYGH9hTe7cpchSFWbTK
Angular doesn't do anything special when you have a form with an action defined. It's pure html form submission with exactly the fields that are defined.
Normally you would use:
<input type="hidden" ng-model="content.desc">
but angular currently (1.2.0rc1) still doesn't support ng-model binding to hidden inputs.
The workaround is this:
<input type="text" name="text" ng-model="content.text" ng-hide="true">

AngularJS - How to trigger submit in a nested form

I'm building a form that generates an invitation when submitted. The invitation has several fields, one of which is an email address input with an 'add' button, which when clicked should add that address to a list of email addresses that should receive the invite.
This can be done with a single form, however if the user hits the enter key while typing an email then it triggers submit on the whole form. I'd like to have the enter key result - when the email input field is focused - have the same effect as clicking the 'add' button. I expected that the proper way to solve this would be to nest an email entry form within the invitation form, something like this:
<ng-form ng-submit="sendInvite()">
<input type="text" placeholder="Title" ng-model="invitation.title"/>
<ng-form ng-submit="addInvitee()">
<input type="email" placeholder="Title" ng-model="inviteeEmail"/>
<button class="btn" type="submit">add</button>
</ng-form>
<button class="btn" type="submit">Send</button>
</ng-form>
With the following javascript in the controller:
$scope.addInvitee = function() {
$scope.invitation.emails.push($scope.inviteeEmail);
$scope.inviteeEmail = '';
}
$scope.sendInvite = function() {
//code to send out the invitation
}
My problem is that having nested the forms (and in doing so converted from <form> to <ng-form>, submitting either one no longer works.
Plunker here
I've similar requirement - wizard driven multi-step form. When user clicks 'Next' button, I've to validate the current step form.
We can trigger validation by firing '$validate' event on the scope bound to the form.
isFormValid = function($scope, ngForm) {
$scope.$broadcast('$validate');
if(! ngForm.$invalid) {
return true;
}
}
When ever I want to check if the form values are correct, I'll call isFormValid with the scope & form instance.
Working code: Plunker link
It is also useful to have few additional logic in isFormValid (included in the above Plunker) which makes the form & form fields $dirty as we would be showing/hiding validation messages based on their $dirty state.
You can use one of the following two ways to specify what javascript method should be called when a form is submitted:
* ngSubmit directive on the form element
* ngClick directive on the first button or input field of type submit (input[type=submit])
-- form docs
<ng-form>
<input type="text" placeholder="Title" ng-model="invitation.title"><br>
<ng-form>
<input type="email" placeholder="Title" ng-model="inviteeEmail">
<button class="btn" ng-click="addInvitee()">add</button><br>
</ng-form>
<ul class="unstyled">
<li ng-repeat="invitee in invitation.invitees">
<span>{{invitee.email}}</span>
</li>
</ul>
<button class="btn" ng-click="sendInvite()">Send</button>
</ng-form>
Plunker
When the form is submitted, you can find all nested forms using some thing like below
forms = []
forms.push(form)
nestedForms = _.filter(_.values(form), (input) -> (input instanceof form.constructor) and (input not in forms))
Here, form is the outer form controller which was submitted. You can hook this code on ur onsubmit, and find all nested forms and do whatever you have to.
Note: This is coffeescript

jQueryUI datepicker issue in append method

okay so i have this page im making, the navigation panel is simple, when i click a link according the the link name it appends the html into the content area, here is the append script for this section
So my goal is where the input box is the ID datepicker im trying to use the jQueryUI datepicker function from jQuery, i tested a regular input box in the actual BODY and not through the append method and it works fine, my issue is im guessing the single vs the double qoutation marks, the ' vs "
how can i solve this issue?
else if (this.id == "tour"){
$("#content").empty();
$("#content").append("<p>\
<h2> Add Tour Dates </h2>\
<form action='tourdates.php' method='post'>\
<input type='text' name='title' placeholder='Title' id='title'>\
<input type='text' name='venueName' placeholder='Vanue Name' id='venueName'>\
<input type='text' name='venueStreetAdress' placeholder='Location Street Adress' id='venueStreetAdress'>\
<input type='text' name='venueCity' placeholder='City' id='venueCity'>\
<input type='text' name='venueState' placeholder='State' id='venueState'>\
<input type='text' name='venueZip' placeholder='Postal Code' id='venueZip'>\
<input type='text' name='datepicker' id='datepicker'>\
<input type='text' name='time' placeholder='Time' id='time'> </p>\
");
If you have a strong feeling that there's something to do with your quotation mark, try to narrow down the problem: Have you tried to put this in a separated variable and make the reference there?
var htmlStuff = "<p>\
<h2> Add Tour Dates </h2>\...";
$("#content").append(htmlStuff);
But I don't think your problem is related to double/single quotes, but with the asynchronous operation of setting up a link to append HTML and try to assign an UI widget before the components exist in the DOM.
Although I find this very bad for code readability, one option would be to append another call to a function that defines the DatePicker (like a "callBack") right after your append. It should work, e.g.:
$('something').append(" <html stuff> ").defineDatePicker();
function defineDatePicker(){
$('one of the elements within that html stuff').datepicker();
}

How to prefill website form fields that are not posted

I don't really know exactly how to search for this on the web. I have a form with one input for telephone. Telephone is optional. I would like to have the word "(Optional)" in the form field. This I have done already like this:
<input type="text" name="billing[telephone]" value="<?php echo $this->__('(optional)') ?>" onFocus="if(this.value == '<?php echo $this->__('(optional)') ?>') {this.value = '';}" onBlur="if (this.value == '') {this.value = '<?php echo $this->__('(optional)') ?>';}" title="<?php echo $this->__('Telephone') ?>" class="input-text" id="billing:telephone" />
It works this way but it posts "(Optional)" everywhere, sends "(Optional)" out in customer emails etc. I would like to make it where if no phone number was inputted it doesn't post "(Optional)" and just leaves the field blank as if nothing was entered.
This code above is from Magento Shopping cart that I added the Optional code in.
Thank you
You could try using the placeholder parameter like so:
<input type="text" name="phone" placeholder="(###) ###-#### (optional)">
It will put in a temporary value to help the user, but will not be posted if the user does not input their own answer. It will also disappear on focus to allow the user to fill in their own answer without having to delete the "optional" text.
The placeholder technique is new in HTML5 :
<input type="text" name="phone" placeholder="(###) ###-#### (optional)">
I think this above line will not support browser compatibility