"Refresh your Backbone app by hitting the Enter key and watch as a new

When I click [edit] (after already committing a word/definition), my goal is for the updateOnEnter method to save the changes made to the definition field, lose focus, and make the field uneditable. However, when I press Enter, the cursor unexpectedly moves to the line below and the field expands in size.

If you'd like to see the CodePen example, you can find it here: http://codepen.io/anon/pen/zxBZBe

var EntryView = Backbone.View.extend({
            model: new Entry(),
            tagName:'div',

            events:{
                'click .edit': 'edit',
                'click .delete': 'delete',
                'keypress .definition': 'updateOnEnter'
            },

            delete: function(ev){
                ev.preventDefault;
                dictionary.remove(this.model);
            },

            edit: function(ev){
                ev.preventDefault;
                this.$('.definition').attr('contenteditable', true).focus();
                // this.$el.addClass('editing');
            },
            close: function(){
                var definition = this.$('.definition').text();
                this.$('.definition').removeattr('contenteditable');
                this.model.set('definition', definition);

            },

            updateOnEnter: function(ev){
                if(ev.which == 13){
                    this.close();
                }
            },

            initialize: function(){
                this.template = _.template($("#dictionary_template").html());

            },

            render: function(){
                this.$el.html(this.template(this.model.toJSON()));
                return this;
            }
        });

Answer №1

You have a slight error in your close method that is causing the code to halt execution prematurely.

this.$('.definition').removeattr('contenteditable');

The correct syntax should be:

this.$('.definition').removeAttr('contenteditable'); // Make sure 'A' in removeAttr is capitalized.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Need help with fixing the problem in my side menu bar and making the content scroll smoothly

Check out my code on JS Fiddle here: http://jsfiddle.net/kodi/d2s3uja0/1/ I'm having trouble getting my side menu bar fixed and the content to scroll. I want to display the menu vertically on the left just like this: M E N U Any suggestions on how ...

Converting objects into arrays in JavaScript: A comprehensive guide

Given the following object : var fix_num : 0; kwT: { "0": 10.2, "1": 0, } I am trying to figure out how to convert it into an array with this specific format : [fix_num.key_of_object_kwT, fix_num.key_of_object_kwT, ... etc] The d ...

invoking a boolean type JavaScript function

I'm currently working on calling a Page Method using AJAX. Take a look at the code below: <asp:Button ID="btn_upload" runat="server" CssClass="btnEffects" Text="Upload" onclick="btn_upload_Click" OnClientClick="return Validate();" /> ...

Establishing connection with SignalR JavaScript client

I'm unfamiliar with SignalR and I find myself feeling lost. My task is to establish a connection to a stream and retrieve certain data. The owner provided some guidance, but they are unsure how to accomplish this using JavaScript. They shared the fol ...

Exploring nested JSON objects with Alasql

I am currently working with a JSON object that represents two companies, Ebay and Amazon. For the Ebay Object: { __v: 0 _id: "56e192f0aea7131c15513328" headquarters: "New York" name: "Ebay" productCategories: [{ _id: "56e193be ...

The middleware for Node.js passport local authentication does not seem to be getting invoked

I am facing an issue with local authentication using passport. The documentation makes it seem simple, but for some reason, the middleware does not run when I call passport.authenticate. Nothing happens at all. After submitting the signup form, the post s ...

Utilizing a JavaScript variable in Jquery for managing an mp3 playlist

I am working on implementing an album feature for the jPlayer that is already in use. Here is the current static code: $(document).ready(function(){ new jPlayerPlaylist({ jPlayer: "#jquery_jplayer_1", cssSele ...

What is the syntax for declaring a boolean or object type?

Is it possible to create a variable in TypeScript that can hold either true/false or an object of booleans? I'm still learning TS and would like some input on this syntax. variableA: { a: boolean, b: boolean } | boolean I found a workaround for now, ...

Angular and dropdowns: a perfect match

Imagine having a controller like this: myApp.controller('testCtrl', function ($scope) { $scope.cars = [ { carId: '1', carModel: 'BMW', carOwner: 'Nader' }, { carId: '2', carModel: &apos ...

Having trouble with router.push in Vue3 and Vuex4?

Encountering some issues with Vue 3 and Vuex. Attempting to redirect users when logged in within my Vuex file, but the redirection is not happening as expected. No errors are being returned, only a link change without actually redirecting to another page. ...

What is the best way to concatenate JSON in JavaScript?

How do I merge this JSON data accordingly: complements = ["XYZ 3, CDE TR, AAA 5", "", "NDP 3, DDD FR"] ? Each address may have multiple complements that need to be combined and separated by a comma. Note: JavaScript is bein ...

Tips for successfully implementing an Ocrad.js example

I've been working on an OCR (optical character recognition) web application and stumbled upon the Ocrad.js JavaScript library Ocrad.js. It seems like a perfect fit for what I need, but unfortunately, I'm having trouble getting it to function prop ...

Leverage both props and destructuring in your Typescript + React projects for maximum efficiency!

Is it possible to use both destructuring and props in React? For instance, can I have specific inputs like name and age that are directly accessed through destructuring, while also accessing additional inputs via props? Example The desired outcome would ...

Learn how to dynamically highlight a table row when any changes are made to it using jQuery

Is there a way to automatically highlight the current table row when any input text or image is changed within that specific row using jQuery? In the given code snippet below, with two rows provided, how can one of the rows be highlighted upon modifying ...

The jQuery date picker refuses to function correctly when I attempt to initialize it after an AJAX call

I am facing an issue with my jquery-ui datepicker not working within the document.ready function after making an ajax call. However, it works fine when I add it inside the ajax complete function. Can someone please provide assistance on what could be cau ...

What steps should I take to ensure the text layout algorithm effectively scales the text based on the "font size" option when using SVG paths?

I have included a fully functional JavaScript code snippet at the end of this post, demonstrating how Hebrew text can be displayed in a "stretched" layout design, as referenced here. The output shows the text in various font sizes: 32 The text appears mos ...

Move a <div> using a handle (without using JQuery)

I devised a plan to create a moveable div with a handle and came up with this code snippet: var mydragg = function() { return { move: function(divid, xpos, ypos) { divid.style.left = xpos + 'px'; divid.style.top = ypos + &apo ...

Navigating through an array of latitude and longitude pairs during an AJAX request

Just starting out with PHP/AJAX and I could use some guidance. Currently, I have a leaflet map where I'm attempting to link two AJAX calls together. The initial AJAX call retrieves data based on a selected country ISO code. Subsequently, I've ut ...

Endless Loop Issue with Google Maps API Integration in NextJS-React

Currently struggling to troubleshoot an infinite loop issue in my React function component map. I've spent a considerable amount of time analyzing the code and suspect that it might be related to the useEffects, but I'm unable to resolve it. Atta ...

Execute a new GET request in Node.js to retrieve data from the server

Hello, I'm currently working on a project for an online course and I've encountered a challenge that I hope you can help me with. The code reviewer has pointed out a specific area where I need to make a change, but I'm having trouble unders ...