Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone: View has lost contact to element
    primarykey
    data
    text
    <p>I have some sort of ViewCollection which renders all sub views.</p> <pre><code>define( ['jquery', 'underscore', 'backbone', 'text!templates/main/layout.html', 'text!templates/main/index.html', 'views/security/login', 'views/security/registration'], function($, _, Backbone, LayoutTemplate, ContentTemplate, LoginView, RegistrationView) { var IndexView = Backbone.View.extend({ tagName: "div", className: "container", template: LayoutTemplate, render: function() { this.$el.html(LayoutTemplate); this.$('div.content').html(ContentTemplate); this.$('div.sidebar').append(new LoginView().render().el); this.$('div.sidebar').append(new RegistrationView().render().el); return this; } }); return IndexView; }); </code></pre> <p>This works quite good! Unfortunatly I have noticed that for example the LoginView can't handle events anymore.</p> <pre><code>define( ['jquery', 'underscore', 'backbone', 'text!templates/security/login.html'], function($, _, Backbone, LoginTemplate){ var LoginView = Backbone.View.extend({ tagName: "form", className: "login well", template: LoginTemplate, events: { "submit form.login": "submit" }, render: function(){ this.$el.html(this.template); return this; }, submit: function(e){ e.preventDefault(); var credentials = { 'username': $(e.target[1]).val() , 'password': $(e.target[2]).val() }; console.log(JSON.stringify(credentials)); $.ajax({ url: '/session' , type: 'POST' , contentType: 'application/json' , data: JSON.stringify(credentials) , success: function() { window.Router.navigate('node', { trigger: true }); } , error: function(xhr, status, error) { console.log([xhr, status, error]); $(e.target[1]).closest('div.control-group').addClass('error'); $(e.target[2]).closest('div.control-group').addClass('error'); } }); } }); return LoginView; }); </code></pre> <p>Instead of sending an ajax call the browser tries to submit the form data url-encoded as GET request that is a sign that the view doesn't listen on any views anymore...</p> <p><strong>Is there a option how I can rebind the view events to the element?</strong></p> <p>login.html</p> <pre><code>&lt;fieldset&gt; &lt;legend&gt;login&lt;/legend&gt; &lt;div class="control-group"&gt; &lt;label class="control-label" for="_session_username"&gt;username:&lt;/label&gt; &lt;div class="controls"&gt; &lt;input type="text" id="_session_username" name="session[username]" placeholder="george78" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="control-group"&gt; &lt;label class="control-label" for="_session_password"&gt;password:&lt;/label&gt; &lt;div class="controls"&gt; &lt;input type="password" id="_session_password" name="session[password]" placeholder="••••••" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;button type="submit" class="btn btn-primary"&gt;login&lt;/button&gt; &lt;/fieldset&gt; </code></pre> <p>the form tags are defined in the view also the .login class attribute.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload