Hi I'm trying to create a select list as part of a login form. The form submits and passes the two input text values but doesn't see the select list.
<form id="form-login" {{action 'authenticate' on='submit'}}>
<fieldset>
{{input id='identification' value=identification placeholder='Username'}}
{{input id='password' value=password placeholder='Password' type='password'}}
<select id="language" name="language">
<option value="ENG">English</option>
<option value="">Not English</option>
</select>
</fieldset>
{{#if errorMessage}}
<div>
<strong>Login failed:</strong> {{errorMessage}}
</div>
{{/if}}
<button type="submit" class="btn btn-default">Login</button>
</form>
I tried these steps but it says they're deprecated and don't work? http://emberjs.com/api/classes/Ember.Select.html
{{view "select" content=languages value=selectedLanguage}}
That's the only page on their documentation I could find?
Thanks!
The selected value needs to be set on the context. Right now the value isn't being set at all.
controller
import Ember from 'ember';
export default Ember.Controller.extend({
language: 'English',
languages: ['English', 'Non English'],
actions: {
authenticate() {
// Set values from form and submit to server...
}
}
});
template
<form id="form-login" {{action 'authenticate' on='submit'}}>
<fieldset>
{{input id='identification' value=identification placeholder='Username'}}
{{input id='password' value=password placeholder='Password' type='password'}}
<select onchange={{action (mut language) value="target.value"}} id="language" name="language">
{{#each languages as |languageChoice|}}
<option value={{languageChoice}} selected={{eq language languageChoice}}>{{languageChoice}}</option>
{{/each}}
</select>
</fieldset>
{{#if errorMessage}}
<div>
<strong>Login failed:</strong> {{errorMessage}}
</div>
{{/if}}
<button type="submit" class="btn btn-default">Login</button>
</form>
Here's a post with a good explanation of everything that's going on.
Related
I'm new to ember and trying to build a very simple app as a learning exercise in 2.4. I have a list of tasks that appear on the index page. And I've attached actions to each one to delete. And have one form row on the bottom of the page with an action to saveTask.
I have one index controller.
No defined index routes.
One model for tasks at app/models/task.js
My function to saveTask is working. But I can't get the deleteTask to work. I know I'm not passing the object I want to delete correctly. The error returned is that Uncaught TypeError: undefined is not a function index.js:26
deleteTask.
Can someone explain the correct syntax to me?
app/templates/index.hbs
{{#each model as |task| }}
<div class="form-horizontal form-group row">
<div class="col-xs-4 col-md-3">
{{input type="text" value=task.taskname class="form-control"}}
</div>
<div class="col-xs-3 col-md-2">
{{input type="text" value=task.startdate class="form-control"}}
</div>
<div class="col-xs-3 col-md-2">
{{input type="text" value=task.enddate class="form-control"}}
</div>
<div class="col-xs-3 col-md-2">
{{input type="text" value=task.duration class="form-control"}}
</div>
<div class="col-xs-3 col-md-2">
{{input type="text" value=task.banding class="form-control"}}
</div>
<div class="col-xs-2 col-md-1">
<button type="button" class="btn btn-default btn-sm" aria-label="Remove task" {{action 'deleteTask' task}}>
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</div>
</div>
{{/each}}
and the controller
app/controllers/index.js
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
deleteTask(task) {
this.destroyRecord();
this.transitionTo('index');
}
}
});
You call destroyRecord in deleteTask on this not on the task, which is actually the record. I think that's all.
You should be able to see in developer tools the line in code which throws. I bet it's this.destroyRecord();.
I am implementing crud operation in my Ember project. I passed an object to the component and tried to use the same object for save, update action.
In route I created model as follows,
routes.js
model() {
return Ember.RSVP.hash({
employeeList : this.store.findAll("employee"),
employee : Ember.Object.create(),
});
}
component: employee-form.js
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="control-label col-sm-3" for="fname">First Name:</label>
<div class="col-sm-8">
{{input type="text" value=model.firstName placeholder="First Name"}}
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="lname">Last Name:</label>
<div class="col-sm-8">
{{input type="text" value=model.lastName placeholder="Last Name" }}
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="email">Email:</label>
<div class="col-sm-8">
{{input type="text" value=model.email placeholder="Email" }}
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="department">Department: </label>
<div class="col-sm-8">
{{input type="text" value=model.department placeholder="Department" }}
</div>
</div>
</form>
I am passing object to component as follows,
Template.hbs
{{employee-form model=model.employee}}
I need to clear the attributes data in object for using it for different operation. I tried to replace the model object with a new ember object and it worked. But I don't think it is a nice way to do, as it is creating new object always.
this.set("model", Ember.Object.create());
Can anyone help me with best approach to clear ember object attributes values.
Use rollbackAttributes()
RollbackAttributes -
If the model hasDirtyAttributes this function will discard any unsaved changes. If the model isNew it will be removed from the store.
model.rollbackAttributes();
I am working in a django application where braintree is used for payment purpose. The braintree version I am using is 3.13.0. I am using the braintree.js dropin-ui alongside the braintree app.
I tried to add a payment method using a custom form with fields 'cardholder_name','number' and 'expiration_date'. When I click on the 'Add Payment Method' link, a server-side request is sent to get the client token. Using that I set up braintree as given below :
function setup_braintree(){
$.ajax({
url:'/get_token/',
type: 'GET',
datatype:'json',
data: {
payment_freq: 1,
},
success: function(d) {
if (d !== null){
$('#dropin-container').html('');
braintree.setup(d.client_token, "dropin", {
container: "dropin-container"
});
}
}
});}
My form is as given below:
<form name="PaymentMethodForm" id="PaymentMethodForm" action="/payment_method/add/" method="POST">{% csrf_token %}
<div id="dropin-container" style="display:none;">Loading...</div>
<div class="form-group">
<label for="id_name_on_card">Name On Card:</label>
<input type="text" id="id_name_on_card" name="name_on_card" value="" class="form-control"/>
</div>
<div class="form-group">
<label for="id_card_number">Card Number:</label>
<input type="text" id="id_card_number" name="card_number" value="" class="form-control"/>
</div>
<div class="form-group">
<label for="id_expiration_date">Expiration Date:</label>
<input type="text" id="id_expiration_date" name="expiration_date" value=""class="form-control"/>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" id="submit" class="btn btn-default">Save</button>
<input type="submit" class="cool-fc button swagbutton" value="Submit" id="submitbutton" name="submitbutton" style="display:none">
</div>
</form>
As per the documentation, a 'hidden' field 'payment_method_nonce' is created, but its value is null.
When I submit the form, 'nonce is required' error is being returned.
What can be the issue here? My server code is given below:
result = braintree.PaymentMethod.create({
"customer_id": request.user.username,
"payment_method_nonce": request.POST['payment_method_nonce'],
"number":request.POST['card_number'],
"cardholder_name":request.POST['name_on_card'],
"expiration_date":request.POST["expiration_date"],
"options":{
"verify_card":True
}
})
Also is there option in dropin-ui to 'add payment method' without using custom form?
Thanks in advance.
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
For the Drop-in, you don't need to include any input tags, braintree.js will render an iframe with the form inputs inside the div specified in braintree.setup(...). Then when the user submits this form, the payment method nonce should be available to you server-side.
Your form should simply be
<form name="PaymentMethodForm" id="PaymentMethodForm" action="/payment_method/add/" method="POST">{% csrf_token %}
<div id="dropin-container"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" id="submit" class="btn btn-default">Save</button>
<input type="submit" class="cool-fc button swagbutton" value="Submit" id="submitbutton" name="submitbutton" style="display:none">
</div>
</form>
If you would like more control over the styling still have the easiest level of PCI compliance, I would take look at Hosted Fields.
Hope this helps!
I am having trouble following SimpLabs' starting guide for ember-simple-auth.
Following the guides on the home page, word for word, does not work.
When I test my login form, the "authenticate" action goes up to the controller and errors.
Stack:
TypeError: Cannot read property 'authenticate' of undefined
at http://local-03-02-xx.lariatcentral.net/assets/vendor.js:61403:48
at invokeResolver (http://local-03-02-xx.lariatcentral.net/assets/vendor.js:23342:9)
at new Promise (http://local-03-02-xx.lariatcentral.net/assets/vendor.js:23328:9)
at __exports__.default.Ember.ObjectProxy.extend.authenticate (http://local-03-02-xx.lariatcentral.net/assets/vendor.js:61402:16)
at __exports__.default.Ember.Mixin.create.actions.authenticate (http://local-03-02-xx.lariatcentral.net/assets/vendor.js:61176:62)
at apply (http://local-03-02-xx.lariatcentral.net/assets/vendor.js:21143:27)
at superFunction [as _super] (http://local-03-02-xx.lariatcentral.net/assets/vendor.js:17841:15)
at __exports__.default.Ember.Mixin.create.actions.authenticate (http://local-03-02-xx.lariatcentral.net/assets/vendor.js:61234:23)
at apply (http://local-03-02-xx.lariatcentral.net/assets/vendor.js:21141:32)
at superWrapper (http://local-03-02-xx.lariatcentral.net/assets/vendor.js:20721:15)
Code
app/routes/application.js
import ApplicationRouteMixin from 'simple-auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin);
app/controller/login.js
import Ember from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';
export default Ember.Controller.extend(LoginControllerMixin, {
authenticator: 'authenticator:custom'
});
app/templates/login.hbs
<form {{action authenticate on='submit'}}>
<div>
<label for="identification">
<span class="sr-only">Login:</span>
<div class="input-group">
<span class="input-group-addon"><span class=" glyphicon glyphicon-user"></span></span>
{{input type="text" value=identification id="identification" class="form-control" placeholder="Login"}}
</div>
</label>
</div>
<div>
<label for="password">
<span class="sr-only">Password:</span>
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>
{{input type="password" value=password id="password" class="form-control" placeholder="Password"}}
</div>
</label>
</div>
<button type="submit" class="btn btn-block action-sm">Login</button>
</form>
Is there an extra step that the website forgot to mention? I feel like I have checked and rechecked everything...
I have a similar form, when I want to get submitted values in newItem controller, I get 'undefined' values. What's wrong?
<form role="form" {{ action 'add' target="newItem" on="submit"}}>
<h2>New category</h2>
<div class="form-group">
<label>Category title</label>
{{input value=title class="form-control" type="text" placeholder="Title"}}
</div>
<div class="form-group">
<label>Category description</label>
{{textarea value=description class="form-control" placeholder="Description"}}
</div>
<div class="form-group">
{{input type="submit" class="btn" }}
</div>
</form>
App.NewItemController = Ember.ObjectController.extend({
add: function(){
console.log(this.get('title')); // undefined
}
});
Update:
This form is on the ApplicationRoute:
App.ApplicationRoute = Ember.Route.extend({
setupController: function(controller, model) {
var newItem = this.controllerFor('NewItem');
controller.set('newItem', newItem);
}
});
You should try using Ember.TextField and Ember.TextArea:
<form role="form" {{ action 'add' target="newItem" on="submit"}}>
<h2>New category</h2>
<div class="form-group">
<label>Category title</label>
{{view Ember.TextField valueBinding="title"}}
</div>
<div class="form-group">
<label>Category description</label>
{{view Ember.TextArea valueBinding="description"}}
</div>
<div class="form-group">
{{input type="submit" class="btn" }}
</div>
</form>
The title and description values are now bound to the corresponding input fields.
Update:
I see your target is the newItem controller, so my guess is that this form is not bound to the NewItemController, thus the values are not bound to the NewItemController. A solution:
App.MyFormController = Ember.Controller.extend({
needs: ['newItem']
add: function(){
var newItemController = this.get('controllers.newItem');
newItemController.add(this.get('title'), this.get('description'));
}
});
App.NewItemController = Ember.ObjectController.extend({
add: function(title, description){
// add the new item here
}
});