How to submit ionic form with the ion-footer submit button? I am trying this http://play.ionic.io/app/07e251b1e926 - angularjs

I have a FORM inside Ion-content and I want to submit that FORM from the button placed inside Ion-footer with all the form validations. Structure of the code at http://play.ionic.io/app/07e251b1e926,
But It is not triggering submit event.Anyone has done this?

Try this, Add label outside form as button and add hidden button inside form also.
<form name="myform" ng-submit="submitmyform()" >
<input type="submit" id="submit" value="Submit" style="display:none"/>
then footer label give for attribute set thebutton id in the form
<label style="width:100%;heigh:30px;background-color:red" for="submit">Submit</label>
Also Should include controller [formController] outside form also.
http://play.ionic.io/app/0e22c14ea697

Using the latest version of Ionic ion-footer you need to add your form again within the footer tags. Footer should be after ion-content close. I did this and now my form can scroll behind the footer and has an extra item-worth of padding at the bottom!
<ion-header>
<ion-navbar>
<ion-title>New Project</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<form [formGroup]="newProjectForm" (submit)="addProject()" novalidate>
<ion-list>
<ion-item>
<ion-label color="primary" stacked>Project Title</ion-label>
<ion-input formControlName="title" clearInput></ion-input>
</ion-item>
</ion-list>
</form>
</ion-content>
<ion-footer>
<form [formGroup]="newProjectForm" (submit)="addProject()" novalidate>
<ion-toolbar>
<button ion-button block color="green" type="submit">
Save
</button>
</ion-toolbar>
</form>
</ion-footer>

This is what helped me on ionic 3, FormBuilder with validation.
<ion-content padding>
<form (ngSubmit)="login()" #loginForm="ngForm">
<ion-list>
<ion-item>
<ion-label floating>Email</ion-label>
<ion-input type="text" [(ngModel)]="form.email" name="email"></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Password</ion-label>
<ion-input type="password" [(ngModel)]="form.password" name="password"></ion-input>
</ion-item>
</ion-list>
</form>
</ion-content>
<ion-footer>
<ion-toolbar>
<button ion-button block full large clear [disabled]="!loginForm.form.valid" (click)="loginForm.ngSubmit.emit()">Login</button>
</ion-toolbar>
</ion-footer>

you can use this code in ionic2:
<ion-content>
<form (ngSubmit)="login()" #loginForm="ngForm">
<ion-list>
<ion-item>
<ion-label>Email</ion-label>
<ion-input type="text" [(ngModel)]="form.email" name="email"></ion-input>
</ion-item>
<ion-item>
<ion-label>Password</ion-label>
<ion-input type="password" [(ngModel)]="form.password" name="password"></ion-input>
</ion-item>
</ion-list>
</form>
</ion-content>
<ion-footer>
<button ion-button full (click)="loginForm.ngSubmit.emit()">Login</button>
</ion-footer>

Maybe this is a better alternative if you are using FormBuilder instead of ngModel.
Put this code after the form crated in your .ts file.
this.signForm.statusChanges
.subscribe(status => this.formIsValid = status);
In the .html file you can check if the form is valid like this.
<button ion-button round large color="secondary" float-right [disabled]="!formIsValid" (click)="onSubmit()">Save</button>

I know is old question, but the best way i see:
<div>
<form id="my-form">
<label for="name">Name:</label>
<input type="text" name="name"></input>
</form>
<!-- ... -->
<button type="submit" form="my-form">Submit</button>
</div>

Related

ERROR Error: Cannot find control with name in ionic3?

I have create a app using ionic 3 and i click on the login link i got this error "Cannot find control with fname, email,number,gstNumber and i have tried formGroupName instead of the formControlName but still not working Please help me for figuring out what I am doing wrong and i have include the page of login and createAccount? `
import { Component } from '#angular/core';
import { NavController } from 'ionic-angular';
import { CreateAccountPage } from '../create-account/create-account';
import { LoginPage } from '../login/login';
#Component({
selector : 'page-home',
templateUrl : 'home.html'
})
export class HomePage {
constructor(public navCtrl : NavController) {
}
openLoginPage() {
this.navCtrl.setRoot(LoginPage);
}
openCreateAccount(){
this.navCtrl.setRoot(CreateAccountPage);
}
}
<ion-content class="masters" >
<ion-card>
<img src="assets/imgs/riseBgdd.jpg" height="550px">
<button class="card-button button-color-yell" color="light" outline small ion-button style="left:90px" (click)="openLoginPage()" >
Login
</button>
<button class="card-button1 button-color-blue" color="light" outline small ion-button style="left:150px" (click)="openCreateAccount()" >
Create Account
</button>
</ion-card>
</ion-content>
//This is our Creat account page
<!DOCTYPE html>
<ion-content>
<h3 text-center>
Create Account
</h3>
<form [formGroup]="createAccountForm" >
<ion-list>
<ion-item class="round-inp centerIt">
<ion-input formControlName="firmName" type="text" placeholder="Firm name" >
</ion-input>
</ion-item>
<br>
<ion-item class="round-inp centerIt">
<ion-input formControlName="yourName" type="text" placeholder="Your name" [(ngModel)]="yourName">
</ion-input>
</ion-item>
<br>
<ion-item class="round-inp centerIt">
<ion-input formControlName="email" type="email" placeholder="Email" [(ngModel)]="email">
</ion-input>
</ion-item>
<br>
<ion-item class="round-inp centerIt">
<ion-input formControlName="mobileNumber" type="number" placeholder="Mobile number" [(ngModel]="mobileNumber">
</ion-input>
</ion-item>
<br>
<ion-item class="round-inp centerIt">
<ion-input formControlName="gstNumber" type="number" placeholder="GST number" [(ngModel)]="firmName">
</ion-input>
</ion-item>
</ion-list>
</form>
</ion-content>
<!DOCTYPE html>
<ion-content class="masters">
<br>
<div class="centerIt">
<ion-img src="assets/imgs/icon image.jpg"
width="60" height="60"
class="app-icon">
</ion-img>
</div>
//This is our login page
<form [formGroup]="loginForm" (submit)="loginUser($event)">
<ion-list>
<ion-item class="round-inp centerIt">
<ion-label>
Email or Phone
</ion-label>
<ion-input formControlName="email" type="text" value=""></ion-input>
</ion-item >
<br>
<ion-item class="round-inp centerIt">
<ion-label>
Password
</ion-label>
<ion-input formControlName="password" type="password"></ion-input>
</ion-item>
<br>
<br>
<div class="centerIt">
<button ion-button outline
class="button-color-yellow"
(click)="openSelectCategory()">
Login
</button>
<button ion-button outline
class="button-color-yello"
(click)="openCreateAccount()">
Create Account
</button>
</div>
<br>
<br>
<div class="centerIt">
<a href="openLogin()" class="link-align-color" >
Forgot Password
</a>
</div>
</ion-list>
</form>
</ion-content>
`
You can change your object from any to FormGroup type:
private createAccountForm : FormGroup
I'm pretty sure, that you don't need ngModel. Try also the other method of binding:
formControlName
<ion-item>
<ion-label floating>Email</ion-label>
<ion-input formControlName="email" type="email"></ion-input>
</ion-item>
[formContol]
<ion-item>
<ion-label floating>Password</ion-label>
<ion-input [formControl]="createAccountForm.controls['password']" type="text"></ion-input>
</ion-item>
I made similar example on plunkr with forms and it just works fine, check it out:
https://plnkr.co/edit/zGenYZz5lzGbWBBTBS9P

how to remove border around ion-toggle

i want to remove the border around the ionic-toggle
<ion-content ng-init="checkarrivee.getAllListeCriteres();">
<div class="swipe" on-swipe-left="warn('Must use scope')">Swipe div</div>
<div class="list" style="width: 95%;margin-left: 2%">
<span us-spinner="{color: 'blue', radius:30, width:8, length: 16}" spinner-key="spinner-0"></span>
<label class="item item-input item-stacked-label">
<span class="input-label">Mission en cours :</span>
<input ion-autocomplete name="vehicule" type="text" readonly="readonly" class="ion-autocomplete"
items-clicked-method="itemsClicked(callback)"
items-removed-method="itemsRemoved(callback)"
placeholder="Séléctionner une mission"
items-method="getMissionEnCours(query)"
external-model="initialCountry"
item-view-value-key="codeDeFicheDeMission"
items-method-value-key="items"
max-selected-items="1"
autocomplete="off"
ng-model="checkarrivee.ficheDeMission"
required/>
</label>
</div>
<ion-list ng-repeat="(key,value) in checkload | groupBy:'Niveau'">
<div class="item item-divider" >{{key}}</div>
<ion-item on-swipe-left="warn('Must use scope')" ng-repeat="var in value" >
<ion-toggle ng-model='checkarrivee.boo[var.id]' ng-click="checkarrivee.isMissionSelected(var.id,checkarrivee.ficheDeMission.id)" toggle-class="toggle-positive">{{var.designation}}</ion-toggle>
<button class="button button-clear icon ion-star button-assertive"
ng-click="toggleStar(var)" ng-show="var.star">
</button>
<ion-option-button class="button-dark" >
<i class="icon ion-star"></i>
</ion-option-button>
</ion-item>
</ion-list>
image:
If you do not want the border to show for the toggle's just add style='border:0;' like this:
<ion-toggle style="border:0;" ng-model='checkarrivee.boo[var.id]' ng-click="checkarrivee.isMissionSelected(var.id,checkarrivee.ficheDeMission.id)" toggle-class="toggle-positive">{{var.designation}}</ion-toggle>
But I would suggest not using inline CSS, and instead adding all styling to your css/scss file as it will become much more difficult to maintain as the project scales.
EDIT:
For the CSS it will be something like this .list .item .noToggleBorder{border:0;}
Here's a codepen for you to check it out.

Change ion-nav-button when form gets valid

Is there a way to disable/enable a ion-nav-button when a form is validated?
As I see, they do not see each other, because i tryed ng-show="myForm.$valid" and it didn´t work.
<ion-nav-buttons side="primary">
<button ng-show="myForm.$valid" class="button button-dark" ng-click="add()">Save</button>
</ion-nav-buttons>
I´ve tryed to get the form in controller side to set ng-show with a boolean variable, but I can´t get it too.
Any help or sugestions?
An CodePen example
Final Edit:
To reference the form from outside, give it a name at the root scope level:
<button ng-show="$root.myForm.$valid">Save</button>
<form name="$root.myForm">
</form>
this will show the button only when the whole form is valid.
Try this code
<ion-nav-buttons side="primary">
<button ng-hide="myForm.$invalid" class="button button-dark" ng-click="add()">Save</button>
</ion-nav-buttons>
<form name="myForm">
<input name="userName" type="text" ng-model="userName" required />
</form>

Value of input tag not updating from a list in AngularJS+Ionic

I am trying to set the value of input equal to the item in ion-list based on a click event. The value updates on first click event but is not updating on later clicks
<ion-view view-title="Add Cities">
<ion-content>
<label class="item-input-wrapper bar-subheader">
<i class="icon ion-android-search placeholder-icon"></i>
<input style="width:100%" type="text" placeholder="Search" ng-model="CityName">
</label>
<ion-button class="button ion-plus button-positive" ng-click="addCity(CityName)" >Add</ion-button>
<div class="list">
<ion-list>
<ion-item ng-repeat="item in states|filter:CityName" ng-click="set(item)">
{{item}}
</ion-item>
</ion-list>
</ul>
</div>
</ion-content>
</ion-view>
associated function in controller.js
$scope.set=function(title){
$scope.CityName=title;
console.log(title);
}
i have checked console the function triggers but the input updates only once
i have tried adding $scope.$apply() in function set but it's still not working. Please suggest edits in the above code or is there a better method to do the same?
The answer is explained here by #Pankaj Parkar
My problem was fixed by renaming ng-model="CityName" to ng-model="data.CityName"
<input style="width:100%" type="text" placeholder="Search" ng-model="data.CityName">
and changing this
$scope.set=function(title){
$scope.CityName=title;
console.log(title);
}
to
$scope.set=function(title){
$scope.data={'CityName':title};
console.log(title);
}

How to show accessory input toolbar using forms in ionicframework?

This is from the docs
This is my code and output
What should be added to show the toolbar with done button?
To be able to see the Done button, you will need to download Cordova keyboard plugin: http://ngcordova.com/docs/plugins/keyboard/
Then use this line:
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false);
Something like this:
module.controller('MyCtrl', function($scope, $cordovaKeyboard) {
$cordovaKeyboard.hideAccessoryBar(false)
});
This example will work only if you include ngCordova to your Ionic project.
More information can be found here: https://github.com/driftyco/ionic-plugin-keyboard
Keyboard.hideKeyboardAccessoryBar Hide the keyboard accessory bar with
the next, previous and done buttons.
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false);
Precisely the buttons you can see on a top image.
I think it may have to be a form...so our app shows the word done in the toolbar and this is what our code looks like. I don't know for sure but I am guessing the done button shows up when there is a form to be submitted. Give it a go and let me know.
<form ng-submit="authenticate(user)" name="loginform" id="loginform">
<div class="list has-header padding">
<div style="height: 48px;" class="item item-input">
<input type="text" placeholder="Username" ng-model="user.username">
<i class="icon ion-close-circled padding" ng-if="user.username.length" ng-click="resetUsername()"></i>
</div>
<div style="height: 48px;" class="item item-input">
<input type="password" placeholder="Password" ng-model="user.password">
<i class="icon ion-close-circled padding" ng-if="user.password.length" ng-click="resetPassword()"></i>
</div>
</div>
<div style="text-align: center;">
<button type="submit" class=" login button button-full button-positive">Login</button>
</div>
</form>

Resources