CKeditor dialog plugin allows for the inclusion of dynamic content elements that can be set at runtime, similar to the onShow method

When a user clicks or selects an element, I want to display its attributes in a dialog box. Everything works fine initially, but when I close the dialog and open it again for another element, it still shows the previous attributes list. The issue lies in the fact that the attribute list is only updated on page reload.

I need the list to be updated every time the dialog opens for a new element. It should reflect the attributes of the current element being selected.

// Dialog definition.
CKEDITOR.dialog.add( 'abbrDialog', function( editor ) {
let selection = editor.getSelection();
let element = selection.getStartElement();
let elAttributes = Object.keys(element.getAttributes());
let listAttrElements = getListOfItems(elAttributes);
return {
// Basic properties of the dialog window: title, minimum size.
title: 'Attributes',
minWidth: 400,
minHeight: 200,

    // Dialog content.
    contents: [
        {
            id: 'basic',

            elements: listAttrElements
        }
    ],
    onShow: function() {
        console.log('here in on show');
    },

    onOk: function() {
        CKEDITOR.dialog.getCurrent().reset();
    },
    onLoad: () => {
        console.log('loaded')
    }
};

});
function getListOfItems (attrObj) {
return attrObj.map ((el, index) => { return {
type: 'checkbox',
id: index,
label: el,
setup: function( element ) {
console.log('new setup required')
this.setValue( element.getText() );
},
commit: function( element ) {
element.setText( this.getValue() );
}
}});
}

Your assistance is greatly appreciated!

https://github.com/ckeditor/ckeditor4/issues/4906#issuecomment-927666316

Answer №1

Here is my solution:

    Upon encountering the issue, I implemented the following code:
        editor.on('dialogHide', function (evt) {
          if (evt.data.getName()=== 'abbrDialog') {
            editor._.storedDialogs['abbrDialog'] = false;
          }
        });

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

Error on page refresh: Unable to access properties of null while attempting to read 'addEventListener'

Having a couple of HTML pages where I load code snippets using jQuery's .load method. Here is an example from my index.html: $('#rotating-content').load(`./snippets/shared/rotating-content.html`); The "rotating-content.html" contains two Bo ...

How to Boost SEO with AngularJS by Customizing Meta Descriptions for Every Partial

Imagine a scenario where there are two partial pages - Sign Up ('/signup') and Sign In ('/signin'). For the sign up partial, I want to include this meta tag: <meta name="description" content="Sign Up"> Similarly, for the sign i ...

utilize makeStyles to modify button text color

Initially, my button was styled like this: style={{ background: '#6c74cc', borderRadius: 3, border: 0, color: 'white', height: 48, padding: '0 30px', }}> It worke ...

JavaScript Sort function malfunctioning and not correctly sorting

I am having trouble sorting div elements by price values. The code seems to be working fine, but the sorting of numbers doesn't appear to be completely accurate. For example, in my jsfiddle, when the button is clicked, the number 21.35 is displayed a ...

What is the best way to combine a new object with an existing array of objects in JavaScript?

https://i.sstatic.net/QIRzO.png Here is an array that I need to modify by adding the object {"temperature":{"work":30,"home":24}} to the beginning: 0 : {title : "tptp", {"temperature":{"work":30,"home":24}}, lastview:"12-12 21:2"} The code I am using is ...

Triggering the jQuery `one()` event from multiple locations for the same element

On the second open of my modal, I am experiencing unexpected behavior where a .one() event is being triggered from a different location than expected. The first time I click on .modal-trigger, everything works fine. The same goes for clicking on .close-mo ...

Unlocking the potential of resizable bootstrap table columns in React

Currently utilizing a bootstrap table <div class="table-responsive"> <table class="table table-bordered"> <thead> <tr> <th>#</th> <th>Table heading</th> </tr> < ...

What is the best way to pinpoint the origin of the element.style being injected by JavaScript?

I've been tasked with updating a client's WordPress website, but I'm still getting acquainted with the overall structure of the site. When looking at the blog page (), I noticed that posts are displayed within a wrapper labeled #blogleft, a ...

The y-axis max property in Highcharts does not effectively hide plot bands and labels

I have set up two separate jsfiddles to demonstrate my issue. The first jsfiddle represents the desired behavior, while the second one displays the problem I am encountering. In the first jsfiddle (https://jsfiddle.net/n5ua6krj/1/), the y-axis[0] does not ...

Ensuring accuracy within a personalized directive that is implemented numerous times within a single webpage (AngularJS)

Recently, I designed a unique directive that includes various inputs and dropdowns. To ensure proper binding between the outer and inner scopes for two-way data binding, I implemented an isolate scope. This setup allows me to reuse the directive multiple t ...

Continuously update in JavaScript based on a condition, cease updating when the condition no longer

I have a scenario on my page where specific data needs to be refreshed every minute, but at the same time, the user should be able to view and edit certain modals. I want to ensure that when a modal is open, the data refreshes are paused so that the modal ...

When the nav-element is clicked, it will load the new content/file.php into the div with the id of "include."

Seeking the most efficient method to load content from a php file into a designated div on my webpage, prioritizing speed, minimal performance requirements, and ease of implementation. Unsure whether it's preferable to utilize php or javascript for t ...

Store the running of a JavaScript file in memory

It seems highly unlikely that achieving the following is possible without expert confirmation: On page number 1, user and application data is requested as soon as the page loads. Page number 2 utilizes the same script, so requesting the same information w ...

Tips for determining the time and space complexity of this JavaScript code

Here are two codes utilized by my platform to establish relationships between nodes. code1 : const getNodeRelationship = (node1, node2) => { // if node1 and node2 are the same node if (node1 === node2) return null; // check direct parent ...

The functionality of Bootstrap's JavaScript is dependent on the presence of jQuery - Reactjs framework

When attempting to combine bootstrap with reactjs, I encountered an issue with importing Bootstrap.js It seems that Bootstrap's JavaScript requires jQuery Below are some of the import statements I have tried: import $ from 'jquery'; imp ...

Maximizing the potential of NPM modules by harnessing the power of the package.json file

Currently, I am working on developing an NPM module for a command-line tool. Upon installation of the package, it is essential to access and read the user's package.json file. While I understand how to read the file syntactically, my main concern lies ...

Easily transform checkboxes into images using jQuery with no need for external plugins

Is it possible to replace checkboxes with images without using jQuery plugins? I'm hoping to achieve this in just a few lines of code. Thank you. ...

Retrieve the text content and identification value from each list item

I've found myself in a frustrating situation where I have an unordered list structured like this: var liList = $("#first").find("li"); var append = ""; for(var i =0; i< liList.length; i++){ var item = $(liList); append += "<option value ...

jQuery AJAX calls are unsuccessful, while NodeJS requests are running smoothly

I am experiencing an issue with a RESTful web service that returns JSON. Interestingly, a NodeJS command line test application is able to retrieve the JSON data without any problems: Successful NodeJS Application: var request = require("request"); var bt ...

Having trouble with Bing search API not functioning properly with AJAX?

Looking to incorporate Bing's search API using JavaScript. My goal is to allow the user to input a query and retrieve only images from Bing. I attempted to use Ajax for this task. When entering the URL directly in the browser, I successfully retriev ...