Integrating a personalized dropdown feature into the Froala editor within an AngularJS environment

After searching for a JavaScript rich text editor that doesn't use frames and allows easy customization of the toolbar with custom dropdowns, I came across the Froala editor. It also offers AngularJS-friendly directives. Previously, I tried using TextAngular, but it lacked an easy way to add dropdowns.

The Froala editor is well-documented, but I'm facing challenges integrating custom dropdowns through the Angular directive. I need to define and register the dropdown using the editor instance retrieved from the options set in my controller. However, this approach is proving difficult as the editor instance reference is still undefined when trying to define the dropdown. You can find the complete code example here:

http://plnkr.co/edit/PnqnifGE54vMUzk28Jwf

My test code snippet is as follows:

function MainController($scope) {
  var defaultHtml = "<span style=\"color:red\">Hello</span>, world!";

  function addDropdown() {
    var editor = $scope.froalaOptions.froalaEditor;
    editor.DefineIcon("myDropdown", {
      NAME: "myDropdown"
    });
    // Other dropdown configurations here...
  }
  
  // More controller logic and setup here...

}
var app = angular.module("test", [
  "ui.bootstrap", "froala"
]);
app.controller("mainController", MainController);

Uncommenting the call to the addDropdown function causes an error due to the undefined editor instance reference. Besides this issue, everything else works fine. Can anyone provide guidance on the correct approach within the Angular context?

Answer №1

I received helpful responses from both the creator of the AngularJS directive and the Froala support team (much appreciated!), so I cannot take credit for this information. It was too detailed to be a simple comment, hence why I am sharing it here: please refer to https://github.com/froala/angular-froala/issues/44.

Basically, there is no straightforward "Angular-like" method to achieve this task: we still have to "execute those commands on the global $.FroalaEditor object before configuring your editor options". A revised plnkr example can be found here:

http://plnkr.co/edit/HkWCugpVv6jT3tsgEYGZ

In essence, the function appears as follows:

function addDropdown() {
    $.FroalaEditor.DefineIcon("myDropdown", {
      NAME: "cog"
    });
    $.FroalaEditor.RegisterCommand("myDropdown", {
      title: "Example",
      type: "dropdown",
      focus: true,
      undo: true,
      refreshAfterCallback: true,
      options: {
        "v1": "Option 1",
        "v2": "Option 2"
      },
      callback: function(cmd, val) {
        console.log(val);
      },
      refresh: function($btn) {
        console.log("do refresh");
      },
      refreshOnShow: function($btn, $dropdown) {
        console.log("do refresh when show");
      }
    });
}

Additionally, it is important to specify not only the toolbarButtons array (which in V2 indicates the buttons to display in the toolbar only if the editor width is >= 1200), but also toolbarButtonsMD, toolbarButtonsSM, and toolbarButtonsXS to define button visibility at smaller screen widths.

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

Is there a way to assign a role to a user without requiring them to send a message beforehand?

I've been searching for a solution to this issue, but all I could find were instructions on how to assign a server role to someone who has interacted in some way. Is there a way to locate a specific user on a server and assign a role to them without ...

tag directive not functioning properly

I have encountered an issue while trying to create a simple custom directive. When I specify the directive as <div my-info></div> in my HTML file, it works fine. However, when I specify it as <my-info></my-info>, it does not work. ...

Combining Mongoose OR conditions with ObjectIDs

After querying my Team schema, I am receiving an array of ids which I have confirmed is correct. The issue seems to lie in the fact that both home_team and away_team are ObjectIDs for the Team Schema within my OR statement. Team.find({ 'conferenc ...

Using a ternary condition within the ngClick directive

Trying to implement different functionalities based on the type of device. The setting tab is clickable, and in the desktop version, clicking should redirect to a default URL. However, on mobile devices, clicking the same link should open a modal window. ...

Exploring the Integration of Google Maps and Angular Google Places in Angular 2

On my webpage, I am utilizing two components simultaneously: and angular2-google-map-auto-complete from https://www.npmjs.com/package/angular2-google-map-auto-complete. To set the Angular maps key, I have defined it as follows: AgmCoreModule.forRoot({ a ...

Issue with Passport Google Oauth login redirection to successful route

I am currently following a tutorial on setting up Google Oauth in my Express app using Passport.js. The tutorial can be found here. Below are the routes defined in my server.js file: // Code snippet here The server.js file also imports configurations fro ...

Error: React - Module not found. This issue arises when attempting to require the 'express' package from within the installed

Hello, I attempted to install the express package in a React project. However, when I try to import the package inside app.js using: const app = require("express"); I encounter 30 errors all stating: Module not found Error: Can't resolve 'x&ap ...

Local connections are successfully established with Socket.IO, however, external connections are experiencing difficulties

I'm a beginner in Node.js and currently working on a simple chat application. However, I have hit a roadblock. I've tried searching online and using various solutions, but I still can't seem to get it to work. If anyone could lend a hand, ...

When transferring an object from a blade template to a Vue component through props, it may become undefined

I'm facing an issue where I am attempting to send an array from an asynchronous method in the controller to a Vue component using props within a blade template. However, when I try to log it in the Vue component, it shows up as undefined. Here is the ...

Executing mathematical calculations within a JavaScript object

Can an equation be executed inside an object? For instance: var taxes = { gst: '0.10', }; var prices = { first_key: '437.95', total_key: parseFloat(prices.first_key * taxes.gst).toFixed(2), ....... }, }; Or do I n ...

Maintaining the sequence of a PHP associative array when transferring it to JavaScript via ajax

Below is the code from my PHP file: GetUserArray.php $Users = array('7'=>'samei', '4'=>"chaya", '10'=>'abetterchutia'); echo json_encode($Users); Here is the AJAX request I am using: $.ajax({ ...

Can halting an ajax function mid-process prevent it from finishing?

My objective is to convert a video using ffmpeg, which tends to take a considerable amount of time to complete. I'm considering sending an ajax request to the server for this task, but I don't want the user to have to wait until the video convers ...

Unable to locate or modify an item within an array

I have a unique way of organizing my collection, with an array inside. Here's how it looks: const postsSchema = mongoose.Schema({ posts: {type: Array}, }) Now, I want to search for a specific document within this collection. I attempted the follo ...

A guide on converting nested arrays within a JSON file into a table format in Google Sheets (possibly leveraging Javascript?)

After successfully connecting via OAuth2 to retrieve a JSON performance report for shares, I am curious about how to convert this object into a matrix format within Google Sheets. { "id": "ID-23035", "total_gain": 11795.72, "holdings": [ ...

Employing plain Javascript (without the use of jQuery) to concatenate information from two JSON strings - encountering an error due to the absence of

Having a JSON stringified form data like this: {"name":"jack miller", "address":"123 main st"} I aimed to append more records but encountered an error saying "append is not a function." The desired outcome is to have both sets of records in this format: ...

Persistently save retrieved information and store data in MongoDB by utilizing Node.js

I am facing the challenge of continuously making an http.get request to an API that provides location data. I have tried a basic get request to test if the data is being received, and it is. However, the issue is that I need this process to run in a contin ...

Node.js route error: no script MIME types allowed with 'X-Content-Type: nosniff' header present

I'm facing an issue where my css and js files do not load on the second route, but they work perfectly fine on the first route. Could someone explain why this discrepancy occurs? // ********************** INDEX PAGE ******************************* ...

Ways to make a function inside a Node.js script get called by JavaScript in HTML?

At the moment, I am integrating Node.JS with various systems as the backend. My goal is to trigger a function in the Node.JS script from my webpage and retrieve specific values. This illustration outlines my objective: JS --> triggers function --> ...

Is the branch of ExtJS 4.1 TreeStore lazy loading extending?

I am working on implementing lazy loading of tree branches in an MVC application using extjs4.1. The branches are located on different URLs and I have faced several challenges along the way. Unfortunately, at this point, the branching functionality is not ...

Obtain an array containing only the specific values of each object

Currently, I have the following code snippet: <db.collection>.find({ id : { $exists: true } }) This query retrieves all documents containing an id property. However, I am interested in transforming this result into an array that contains only the va ...