Determine the specific Flow.js / ng-flow input (flow-btn) that was utilized for the file upload

I have several flow-btn elements scattered throughout my webpage. Users can either upload individual files directly to a list of items or choose to upload multiple files that will automatically populate the list. This functionality is contained within a flow-init.

Here's an example pseudo-code snippet:

<div flow-init>
    <div flow-btn>Upload multiple images to fill the list</div>
    <h3>The list</h3>
    <ul>
        <li ng-repeat="item in items">
            <div flow-btn flow-single-file>Upload an image for this item</div>
            <img flow-img="item.flowFile">
        </li>
    </ul>
 </div>

I am trying to determine which specific flow-btn was used within the list in order to display the uploaded image thumbnail in the right place. Essentially, I want access to the item from a flow event.

Please note: The loop data for the list is based on other information, so I cannot simply cycle through $flow.files to generate my list.

What would be the best way to achieve this?

Should I create a new separate flow-init instance for each item in the loop? Would this be excessive?

Edit: Alternatively, would it be possible to programmatically trigger the multiple flow-btn from my controller instead of having one for each item? In such a case, I could store the current item in the controller.

Answer №1

Last Updated: August 2015 Upon further examination in Firefox, I discovered that the input element is actually hidden inside event.originalTarget, not event.srcElement. Therefore, I have made updates to the code and Plunker example.


As you may already be aware, ng-flow offers events that allow you to pass functions and inject them with the $event object, providing a reference to the specific button clicked. In this case, you can listen for the flow-files-submitted event and perform appropriate actions based on $event.srcElement, like so:

HTML

<div flow-init flow-files-submitted='handleUpload($files, $event, $flow)'>
     <div flow-btn>Upload multiple images to fill the list</div>
     <h3>The list</h3>
     <ul>
        <li ng-repeat="item in items">
            <div flow-btn flow-single-file>Upload an image for this item</div>
            <img flow-img="item.photo" ng-if='item.photo'>
        </li>
    </ul>
</div>

JS

$scope.handleUpload =  function($files, $event, $flow) {
 if(($event.srcElement !== undefined)&&($event.srcElement !== null))
  var input = angular.element($event.srcElement)
 else
  var input = angular.element($event.originalTarget)
 if (input.scope().item) {
  if(input.scope().item.photo) {
    input.scope().item.photo.cancel();
  }
  input.scope().item.photo = $files[0];
 } else {
   for(var i = 0; i < $files.length; i++) {
     $scope.items.push({photo: $files[i]});
   }
 }
};

Don't forget to visit this Plunker for a solution to your issue!

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 can I easily implement basic password protection on a straightforward Next.js web app hosted on Vercel?

Adding a simple password validation step to a dashboard that only a select few would access. The data is not highly sensitive, but some basic protection is desired to limit unauthorized access. While not expecting targeted attacks from hackers, the goal is ...

What is the correct method for properly disposing of a Three.js Scene in version r55?

It appears that Three.js lacks a proper method for disposing of a THREE.Scene and all its contents. My current approach is as follows: $.each(scene.__objects, function(idx, obj) { scene.remove(obj); ...

Error encountered with $http.get during ng-click execution

edit: to make it clear, I have excluded some input fields and additional code, but all necessary information is included. I have searched extensively online without finding a solution. In my html, I am executing a function userSearch() on ng-click. The ng ...

What is the best way to send a callback function from a React hook back to the parent component, such as returning a collection of uploaded URLs

How can I pass a callback function from a child component using React hooks to the parent component, specifically returning a list of uploaded URLs? Child Components/Hooks import React, { useCallback } from 'react'; import { useDropzone } from ...

What is the best way to assign a JavaScript string to a Java string?

This particular dropdown list allows for multiple values to be selected -- A loop has been utilized to populate the options in the list by fetching data from a database. Here is the javascript function I am attempting to implement in order to retrieve th ...

The ajax function nestled within a nested forEach loop completes its execution once the inner callback function is triggered

I am encountering a problem with an ajax call that is nested within a forEach loop inside another function. The issue is that the callback of the outer function is being triggered before the inner loop completes, resulting in "staticItemList" not being p ...

Enhancing performance by dynamically updating DOM elements when they come into view during scrolling

Currently, I am in search of an efficient algorithm to dynamically load background-images for a group of <li>'s but I am encountering some efficiency issues. The code I am using at the moment is as follows: function elementInView($elem, vps, vp ...

Fill a table using ng-repeat and verify that the header data matches

In my project, I have an array of years that are used to populate the table header row. Additionally, there is an object containing data that populates the table itself. The challenge is to place the correct year data under the corresponding year header. T ...

Consecutive interdependent operations within a Vuex action

I'm currently working on a Vue application that is pulling data from the Contentful API. I have a thumbnail (image) field for each entry and I want to extract the main colors as hexadecimal values and store them in the state for use throughout the app ...

Ensure mydesign is seamlessly integrated with the asp.net page

Recently, I've been working on an Asp.net page and here's a snippet of my code: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="fisrt_page.aspx.cs" Inherits="my_project.fisrt_page" %> <!DOCTYPE html> <html xmlns="http: ...

Vue.js: Resolving the "Unknown Custom Element" Issue with Hot Module Replacement

I have a good understanding of component registration, but I am encountering a challenging issue: Vue.js component Unknown custom element Unknown custom element when nesting components in Vue.js The Issue at Hand While using the development server, I ...

I'm having trouble accessing the JSON object, what could I be overlooking?

I am currently working on accessing an array within an object in my code: export default class App extends Component { constructor(props) { super(props); this.state = { data: {}, isLoading: true } }; componentDidMount() { ...

Passing a parameter in an AngularJS/TypeScript component

I am currently working on a project that involves the integration of angularjs and typescript. Within this project, I have developed a component specifically designed to handle errors. However, I am facing a challenge in retrieving the parameter sent to t ...

Employing Ajax for interacting with a database

I am attempting to query my database using a JavaScript function for the first time, and I am struggling to get it to work. While unsure if this is the correct approach, it is the one that I have come across. Below is a simple snippet of my HTML code: < ...

What is the most efficient way to handle dependencies and instantiate objects just once in JavaScript?

I am interested in discovering reliable and tested design patterns in Javascript that ensure the loading of dependencies only once, as well as instantiating an object only once within the DOM. Specifically, I have the following scenario: // Block A in th ...

I keep getting a "Resource Not Found" error when using Angular's URL template

While working on my page, I encountered an error message related to pagination implementation: angular.min.js:87 GET http://localhost:56485/Areas/EVerify/Views/EVerify/dirPagination.tpl.html 404 (Not Found) My JavaScript file looks like this: var EVerif ...

Organize JSON data in Angular 6 from an observable based on a specific key

Note: While I am familiar with sorting a regular array of objects using .sort(), I am facing a challenge with an observable object that I am not accustomed to. My task involves retrieving a JSON array of objects with a service: import { Injectable } from ...

Utilizing Angular: incorporating a ng-model template into a directive for seamless filtering

I am working on creating a directive that will display the template below and enable easy filtering. The goal is to have the model change when an option from the select list is chosen and a value is entered into the input box. I want the directive to hold ...

What does the error message "unsupported command-line flag" in Chrome mean for Protractor?

Recently jumping on the Protractor bandwagon, I found myself facing an issue while running my tests on Chrome (an error message appears below the address bar in the browser): A worrisome warning popped up saying something about '--ignore-certificat ...

Press on the div to reveal its content at the clicked position

Hello, I have a query that I need help with. I currently have a basic table with buttons in columns that act as filters. When you click on one of these buttons, it opens up a form. https://i.sstatic.net/nuEpq.png What I am trying to achieve is to make t ...