angular-cn/aio/content/examples/forms/js/plnkr.no-link.html

440 lines
13 KiB
HTML

<html lang="en"><head></head><body><form id="mainForm" method="post" action="http://plnkr.co/edit/?p=preview" target="_self"><input type="hidden" name="files[app/app.component.js]" value="(function(app) {
app.AppComponent = ng.core
.Component({
selector: 'my-app',
template: '<hero-form></hero-form>'
})
.Class({
constructor: function() {}
});
})(window.app || (window.app = {}));
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/"><input type="hidden" name="files[app/app.module.js]" value="(function(app) {
app.AppModule =
ng.core.NgModule({
imports: [
ng.platformBrowser.BrowserModule,
ng.forms.FormsModule
],
declarations: [
app.AppComponent,
app.HeroFormComponent
],
bootstrap: [ app.AppComponent ]
})
.Class({
constructor: function() {}
});
})(window.app || (window.app = {}));
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/"><input type="hidden" name="files[app/hero-form.component.js]" value="(function(app) {
app.HeroFormComponent = ng.core
.Component({
selector: 'hero-form',
templateUrl: 'app/hero-form.component.html'
})
.Class({
constructor: [function() {
this.powers = ['Really Smart', 'Super Flexible',
'Super Hot', 'Weather Changer'
];
this.model = new app.Hero(18, 'Dr IQ', this.powers[0],
'Chuck Overstreet');
this.submitted = false;
}],
onSubmit: function() {
this.submitted = true;
},
// TODO: Remove this when we're done
diagnostic: function() {
return JSON.stringify(this.model);
},
//////// DO NOT SHOW IN DOCS ////////
// Reveal in html:
// AlterEgo via form.controls = {{showFormControls(hf)}}
showFormControls: function(form) {
return form.controls['alterEgo'] &amp;&amp;
form.controls['name'].value; // Dr. IQ
},
/////////////////////////////
});
})(window.app || (window.app = {}));
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/"><input type="hidden" name="files[app/hero.js]" value="(function(app) {
app.Hero = Hero;
function Hero(id, name, power, alterEgo) {
this.id = id;
this.name = name;
this.power = power;
this.alterEgo = alterEgo;
}
})(window.app || (window.app = {}));
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/"><input type="hidden" name="files[app/hero-form.component.html]" value="<div class=&quot;container&quot;>
<div [hidden]=&quot;submitted&quot;>
<h1>Hero Form</h1>
<form (ngSubmit)=&quot;onSubmit()&quot; #heroForm=&quot;ngForm&quot;>
<div class=&quot;form-group&quot;>
<label for=&quot;name&quot;>Name</label>
<input type=&quot;text&quot; class=&quot;form-control&quot; required
[(ngModel)]=&quot;model.name&quot;
name=&quot;name&quot; #name=&quot;ngModel&quot; >
<div [hidden]=&quot;name.valid&quot; class=&quot;alert alert-danger&quot;>
Name is required
</div>
</div>
<div class=&quot;form-group&quot;>
<label for=&quot;alterEgo&quot;>Alter Ego</label>
<input type=&quot;text&quot; class=&quot;form-control&quot;
[(ngModel)]=&quot;model.alterEgo&quot;
name=&quot;alterEgo&quot; >
</div>
<div class=&quot;form-group&quot;>
<label for=&quot;power&quot;>Hero Power</label>
<select class=&quot;form-control&quot; required
[(ngModel)]=&quot;model.power&quot;
name=&quot;power&quot; #power=&quot;ngModel&quot; >
<option *ngFor=&quot;let p of powers&quot; [value]=&quot;p&quot;>{{p}}</option>
</select>
<div [hidden]=&quot;power.valid&quot; class=&quot;alert alert-danger&quot;>
Power is required
</div>
</div>
<button type=&quot;submit&quot; class=&quot;btn btn-default&quot;
[disabled]=&quot;!heroForm.form.valid&quot;>Submit</button>
</form>
</div>
<div [hidden]=&quot;!submitted&quot;>
<h2>You submitted the following:</h2>
<div class=&quot;row&quot;>
<div class=&quot;col-xs-3&quot;>Name</div>
<div class=&quot;col-xs-9 pull-left&quot;>{{ model.name }}</div>
</div>
<div class=&quot;row&quot;>
<div class=&quot;col-xs-3&quot;>Alter Ego</div>
<div class=&quot;col-xs-9 pull-left&quot;>{{ model.alterEgo }}</div>
</div>
<div class=&quot;row&quot;>
<div class=&quot;col-xs-3&quot;>Power</div>
<div class=&quot;col-xs-9 pull-left&quot;>{{ model.power }}</div>
</div>
<br>
<button class=&quot;btn btn-default&quot; (click)=&quot;submitted=false&quot;>Edit</button>
</div>
</div>
<!-- ==================================================== -->
<div>
<form>
<!-- ... all of the form ... -->
</form>
</div>
<!-- ==================================================== -->
<hr>
<style>
.no-style .ng-valid {
border-left: 1px solid #CCC
}
.no-style .ng-invalid {
border-left: 1px solid #CCC
}
</style>
<div class=&quot;no-style&quot; style=&quot;margin-left: 4px&quot;>
<div class=&quot;container&quot;>
<h1>Hero Form</h1>
<form>
<div class=&quot;form-group&quot;>
<label for=&quot;name&quot;>Name</label>
<input type=&quot;text&quot; class=&quot;form-control&quot; required>
</div>
<div class=&quot;form-group&quot;>
<label for=&quot;alterEgo&quot;>Alter Ego</label>
<input type=&quot;text&quot; class=&quot;form-control&quot;>
</div>
<div class=&quot;form-group&quot;>
<label for=&quot;power&quot;>Hero Power</label>
<select class=&quot;form-control&quot; required>
<option *ngFor=&quot;let p of powers&quot; [value]=&quot;p&quot;>{{p}}</option>
</select>
</div>
<button type=&quot;submit&quot; class=&quot;btn btn-default&quot;>Submit</button>
</form>
</div>
<!-- ==================================================== -->
<hr>
<div class=&quot;container&quot;>
<h1>Hero Form</h1>
<form>
{{diagnostic()}}
<div class=&quot;form-group&quot;>
<label for=&quot;name&quot;>Name</label>
<input type=&quot;text&quot; class=&quot;form-control&quot; required
[(ngModel)]=&quot;model.name&quot; name=&quot;name&quot; >
</div>
<div class=&quot;form-group&quot;>
<label for=&quot;alterEgo&quot;>Alter Ego</label>
<input type=&quot;text&quot; class=&quot;form-control&quot;
[(ngModel)]=&quot;model.alterEgo&quot; name=&quot;alterEgo&quot;>
</div>
<div class=&quot;form-group&quot;>
<label for=&quot;power&quot;>Hero Power</label>
<select class=&quot;form-control&quot; required
[(ngModel)]=&quot;model.power&quot; name=&quot;power&quot;>
<option *ngFor=&quot;let p of powers&quot; [value]=&quot;p&quot;>{{p}}</option>
</select>
</div>
<button type=&quot;submit&quot; class=&quot;btn btn-default&quot;>Submit</button>
</form>
</div>
<!-- EXTRA MATERIAL FOR DOCUMENTATION -->
<hr>
<input type=&quot;text&quot; class=&quot;form-control&quot; required
[(ngModel)]=&quot;model.name&quot; >
TODO: remove this: {{model.name}}
<hr>
<input type=&quot;text&quot; class=&quot;form-control&quot; required
[ngModel]=&quot;model.name&quot;
(ngModelChange)=&quot;model.name = $event&quot; >
TODO: remove this: {{model.name}}
<hr>
<form>
<input type=&quot;text&quot; class=&quot;form-control&quot; required
[(ngModel)]=&quot;model.name&quot;
name=&quot;name&quot; >
<hr>
<input type=&quot;text&quot; class=&quot;form-control&quot; required
[(ngModel)]=&quot;model.name&quot;
name=&quot;name&quot; #spy >
<br>TODO: remove this: {{spy.className}}
</form>
<div>
<hr>
Name via form.controls = {{showFormControls(heroForm)}}
</div>
</div>
<!--
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
-->"><input type="hidden" name="files[index.html]" value="<!DOCTYPE html>
<html>
<head>
<title>Hero Form</title>
<script>document.write('<base href=&quot;' + document.location + '&quot; />');</script>
<meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;>
<link rel=&quot;stylesheet&quot; href=&quot;https://unpkg.com/bootstrap@3.3.7/dist/css/bootstrap.min.css&quot;>
<link rel=&quot;stylesheet&quot; href=&quot;styles.css&quot;>
<link rel=&quot;stylesheet&quot; href=&quot;forms.css&quot;>
<!-- IE required polyfill -->
<script src=&quot;https://unpkg.com/core-js/client/shim.min.js&quot;></script>
<script src=&quot;https://unpkg.com/zone.js@0.7.4?main=browser&quot;></script>
<script src=&quot;https://unpkg.com/rxjs@5.0.1/bundles/Rx.js&quot;></script>
<script src=&quot;https://unpkg.com/@angular/core/bundles/core.umd.js&quot;></script>
<script src=&quot;https://unpkg.com/@angular/common/bundles/common.umd.js&quot;></script>
<script src=&quot;https://unpkg.com/@angular/compiler/bundles/compiler.umd.js&quot;></script>
<script src=&quot;https://unpkg.com/@angular/forms/bundles/forms.umd.js&quot;></script>
<script src=&quot;https://unpkg.com/@angular/platform-browser/bundles/platform-browser.umd.js&quot;></script>
<script src=&quot;https://unpkg.com/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js&quot;></script>
<script src='app/hero.js'></script>
<script src='app/hero-form.component.js'></script>
<script src='app/app.component.js'></script>
<script src='app/app.module.js'></script>
<script src='main.js'></script>
</head>
<body>
<my-app>Loading...</my-app>
</body>
</html>
<!--
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
-->"><input type="hidden" name="files[forms.css]" value=".ng-valid[required] {
border-left: 5px solid #42A948; /* green */
}
.ng-invalid {
border-left: 5px solid #a94442; /* red */
}
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/"><input type="hidden" name="files[styles.css]" value="/* Master Styles */
h1 {
color: #369;
font-family: Arial, Helvetica, sans-serif;
font-size: 250%;
}
h2, h3 {
color: #444;
font-family: Arial, Helvetica, sans-serif;
font-weight: lighter;
}
body {
margin: 2em;
}
body, input[text], button {
color: #888;
font-family: Cambria, Georgia;
}
a {
cursor: pointer;
cursor: hand;
}
button {
font-family: Arial;
background-color: #eee;
border: none;
padding: 5px 10px;
border-radius: 4px;
cursor: pointer;
cursor: hand;
}
button:hover {
background-color: #cfd8dc;
}
button:disabled {
background-color: #eee;
color: #aaa;
cursor: auto;
}
/* Navigation link styles */
nav a {
padding: 5px 10px;
text-decoration: none;
margin-right: 10px;
margin-top: 10px;
display: inline-block;
background-color: #eee;
border-radius: 4px;
}
nav a:visited, a:link {
color: #607D8B;
}
nav a:hover {
color: #039be5;
background-color: #CFD8DC;
}
nav a.active {
color: #039be5;
}
/* items class */
.items {
margin: 0 0 2em 0;
list-style-type: none;
padding: 0;
width: 24em;
}
.items li {
cursor: pointer;
position: relative;
left: 0;
background-color: #EEE;
margin: .5em;
padding: .3em 0;
height: 1.6em;
border-radius: 4px;
}
.items li:hover {
color: #607D8B;
background-color: #DDD;
left: .1em;
}
.items li.selected {
background-color: #CFD8DC;
color: white;
}
.items li.selected:hover {
background-color: #BBD8DC;
}
.items .text {
position: relative;
top: -3px;
}
.items .badge {
display: inline-block;
font-size: small;
color: white;
padding: 0.8em 0.7em 0 0.7em;
background-color: #607D8B;
line-height: 1em;
position: relative;
left: -1px;
top: -4px;
height: 1.8em;
margin-right: .8em;
border-radius: 4px 0 0 4px;
}
/* everywhere else */
* {
font-family: Arial, Helvetica, sans-serif;
}
/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/"><input type="hidden" name="tags[0]" value="angular"><input type="hidden" name="tags[1]" value="example"><input type="hidden" name="private" value="true"><input type="hidden" name="description" value="Angular Example - Forms"></form><script>document.getElementById("mainForm").submit();</script></body></html>