Ember: Trigger a Function on Input Field Blur with Parameter

Currently, I am in the process of developing a basic Todo App to get familiar with EmberJS version 2.14. One feature I aim to integrate is manual inline editing where users can double-click on a todo item text span to activate an input field for editing. The changes made by the user will be synchronized with a backing object and when focus is removed, the input field should revert back to displaying the edited text.

The code snippet below resides within an {{each}} block helper and it is almost fully functional.

{{#unless todo.isOpenForEdit}}
   <span {{action 'openForEditing' todo on='doubleClick'}}>{{todo.text}}</span>
{{else}}
  {{input type="text" value=todo.text action='closeForEditing' on='focus-out'}}
{{/unless}}

Functioning Components

  • You can successfully enter editing mode by double-clicking (i.e. openForEditing() is correctly triggered).
  • The action handler closeForEditing() is appropriately executed upon losing focus from the input field.

Incomplete Components

  • I am unsure how to pass the todo object model as an argument so that the closeForEditing() function can reset isOpenForEdit to false.

--

Q) How can I pass arguments to an action handler when using the input helper?

Q) Is there an alternative method I could utilize to accomplish my objective?

Answer №1

One way to pass your action is shown below:

{{input type="text" value=todo.text focusOut=(action 'closeForEditing' todo)}}

Answer №2

To enhance todo, one can utilize a closure action by implementing the action helper.

{{input type="text" value=todo.text action=(action 'closeForEditing' todo) on='focus-out'}}

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

How to show line breaks in MySQL text type when rendering in EJS

In my MySQL table, I have a column called PROJ_ABOUT with the type TEXT. I have inserted several rows into this column and now I am trying to display this information in my Express.js app using the ejs engine. <h2>About project</h2> <p> ...

Verify whether the input includes a specific value or a different one

Can someone help me with a simple task of checking if a textarea contains the value "12" OR "34"? I have tried the code below but it doesn't seem to work. Any suggestions? function check() { if (V1.value == ('12' || '34')) { ...

leveraging jQuery across an Angular 2 application as a global tool

I'm currently exploring ways to incorporate jQuery globally throughout my angular 2 application. The only comprehensive resource I've come across so far is this Stack Overflow answer. However, despite my efforts, I haven't been able to make ...

The UNHANDLEDREJECTION callback was triggered prematurely during asynchronous parallel execution

Asynchronously using parallel to retrieve data from the database in parallel. Upon each task returning the data, it is stored in a local object. In index.js, the cacheService.js is called. Inside cacheService.js, data is loaded from both MySQL and MongoDB ...

Content changing programmatically does not reset the scrollHeight

As I embark on the journey to expand my coding skills, I have decided to challenge myself by tackling some tasks without relying on jQuery. One particular challenge that I am currently facing involves a fixed contenteditable div. The goal is to adjust the ...

Controlling Navigation Bar State

Looking to enhance my app by implementing state management for better flexibility. In essence, my app is a React web app integrated with Tableau dashboards. I aim to have specific routes (each containing specific dashboards) dynamically populated in the ap ...

Creating a seamless login experience using Hapi.js and AngularJS

It appears that I may need some clarification, here are the Docs for hapi I have this set up on the backend with hapijs and node.js. server.route({ method: 'POST', path: '/login', handler: function(request, reply) { USER: re ...

Conceal/Inactivate element when scrolling, and once scrolling comes to a halt, reveal it once more

I have been working on creating a div tag to overlay an embed tag and added some javascript to prevent users from right-clicking to download the pdf inside the embed tag (even though it may seem unnecessary, it was requested by my customer). Here is the ma ...

The AddClass function fails to function properly after an ajax form is submitted

I am facing a challenge in setting up validation for my ajax form. My goal is to have a red border appear around the input field if it is submitted empty. Unfortunately, when I try to use addClass(), it does not seem to have any effect. The alert message ...

Can a specific input value be applied or utilized in any way?

I have limited coding experience, so please forgive me if this is a simple question. I am curious if it is possible to create a feature on a website where user input is utilized elsewhere. Specifically, I am looking to have an input box where a user enter ...

Issue in Jquery: Unable to load the corresponding pages when toggling the checkbox on and off

I am facing an issue with a checkbox and calling different php pages based on the status of the checkbox. Currently, the code works only for checked checkboxes. I'm not sure why it's not working for unchecked checkboxes as well. <script type ...

Setting up Babel to effectively function across multiple directories

I've been utilizing Babel for some time now and it effectively transforms my ES Next code to the dist directory using this command: babel src --out-dir dist --source-maps --copy-files Up until now, all my JavaScript code has been stored in the src fo ...

Issue with Wicket: unable to generate sound for resource paths

I am having some trouble with a path in my wicket project. There is a sounds folder located within the Web Pages directory. Within my JavaScript code, I am using the following path to play sounds: audioElement.setAttribute('src', 'sounds/s ...

React does not automatically re-render components created with the built-in function

I'm facing some confusion with the behavior in my code: I've created a component that should function as a menu using MaterialUI. The idea is that when a button in the menu is clicked, it becomes "active" and visually reflects this change by set ...

How is it possible for React to function within the views directory?

In the directory structure of my project, I have a React application housed within the views folder. The root folder contains the model, controller, and views directories. Within the views folder, there is a React app. I am unsure of how to start both si ...

Retrieving Files using Ajax Across Different File Types

I recently came across the following code snippet: DOM_imgDir = "img/UI/DOM/"; fileextension = ".jpg"; $.ajax({ url: DOM_imgDir, success: function (data) { $(data).find("a:contains(" + fileextension + ")").each(function () { filename = thi ...

"Which is better for handling form data: using $.ajax with hidden fields or PHP form

Creating a streamlined admin tool using PHP and JQuery to handle image data management is my current project. The main goal of this utility is to enable an admin to retrieve images from a database, view associated tags for each image, and add new tags as n ...

Typescript-powered React component for controlling flow in applications

Utilizing a Control flow component in React allows for rendering based on conditions: The component will display its children if the condition evaluates to true, If the condition is false, it will render null or a specified fallback element. Description ...

The Discord.js error message popped up, stating that it was unable to access the property 'then' since it was undefined

I'm currently working on implementing a mute command for my discord bot, but I'm encountering an error that says; TypeError: Cannot read property 'then' of undefined I am unsure of what is causing this issue and would greatly apprecia ...

What is the best way to convert an Angular object into a string using a for-loop and display it using $sce in AngularJS?

Currently, I am rendering a block of HTML and directives using $sce.trustAsHtml. To achieve this, I utilized a directive called compile-template which enables the use of ng-directives like ng-click and ng-disabled. While it is possible for me to pass sta ...