Skip to content

Instantly share code, notes, and snippets.

@mistahenry
Last active November 16, 2020 17:23
Show Gist options
  • Save mistahenry/495410d565f6d8a0ccd80241599b29e7 to your computer and use it in GitHub Desktop.
Save mistahenry/495410d565f6d8a0ccd80241599b29e7 to your computer and use it in GitHub Desktop.
prevent a from input
import Component from '@glimmer/component';
export default class extends Component {
}
import Component from '@glimmer/component';
export default class extends Component {
}
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
export default class ApplicationController extends Controller {
@tracked
foo;
appName = 'Ember Twiddle';
@action
updateFoo(event){
let value = event.target.value;
if(value.length > 0 && 'a' === value.charAt(value.length - 1)){
value = value.substring(0, value.length - 1);
}
this.foo = value;
}
}
<h1>Welcome to {{this.appName}}</h1>
<br>
<br>
<div>
<label>Foo:</label>
<FormElement @value={{this.foo}} as |el|>
<el.control @onChange={{this.updateFoo}}/>
</FormElement>
</div>
<div>
<label>Foo Control direct:</label>
<FormInput @value={{this.foo}} @onChange={{this.updateFoo}}/>
</div>
<div>
<label>Foo (ctrl val): </label>
{{this.foo}}
</div>
<br>
<br>
{{yield
(hash
control=(component "form-input"
value=this.args.value
)
)
}}
<input
type="text"
value={{@value}}
{{on "input" @onChange}}
>
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment