Implement Dropdown in RichTextEditor toolbar

Hi, 
I want to implement custom dropdown in RichTextEditor Toolbar and on selecting it the existing placeholder of the richtextbody should not be displayed and selected value of the dropdown should come there.

For reference sharing screen shot in which richtexteditor is having custom dropdown "select placeholder value". but this is in jqx I want in syncfusion using angular.



Thanks in advance

10 Replies

RA RakhiS July 28, 2020 10:32 AM UTC

Hi,
with refrence to this, 

I have added dropdown in Rich Text editor by following the code of stackblitz. Now my requirement is to refresh the datasource of this dropdown, as there is another drop down on my page by selection of that I fill this custorm dropdown, so when the parent dropdown changes I want to refresh the datasource of this custom dropdown. How can I achieve it.

This is not getting possible as the dropdown is created at the initial level, (oncreated) event of rich text editor. Please help


IS Indrajith Srinivasan Syncfusion Team July 28, 2020 12:47 PM UTC

Hi Rakhi, 
 
Greetings from Syncfusion support, 
 
We have validated your reported query. You can change the datasource of the dropdown dynamically, by storing its object in a variable globally and using it later for changing the datasource. We have also prepared a sample that tries to meet your requirements. 
 
 
Please let us now if the solution helps, 
 
Regards, 
Indrajith 



RA RakhiS July 29, 2020 04:52 AM UTC

Hi,
Thanks for the response. I have shared the snippet and code of my implementation.

In the below snippet, I am having dropdown of Workflow/MasterData , on change of which I want to update the fields of dropdown in rich text editor in right hand side.
I used this line of code
 this.dropDownListObject.dataSource = this.placeHolderdata;

on the onChange event of workflow dropdown in which I am getting id, and on that Id basis I make a call to database and get the fields which I want to append into the rich text dropdown which already contains some hardcoded value. The very first time when I used any dropdown element of the workflow it gets appened into the custom dropdown(Rich text editor dropdown). Also when I continously two item one after the other, then the fields from both the selected item get appended (i.e when I open the Rich text editor collapse button). Next time it is already openened and when  I select again from the workflow dropdown and checked in the already opened toolbar of rich text it doesn't get updated. while in console I am getting all the appended values but it is not showing in the dropdown.


I think there is some problem with the collapsible open/close. I also try to use this line of code on beforeopen event of the custom dropdown but still it is not working. 


method I called on the change event of the workflow dropdown:
getEntities() {    
    this._stepcolservice.getAllEntities(this.EntityId) 
      .subscribe(result => {
        for (var i = 0; i < result.length; i++) {
          this.placeHolderdata.push({ Value: result[i].Value, FieldName: result[i].FieldName }) //pushing into the datasource variable to append
        }
        this.dropDownListObject.dataSource = this.placeHolderdata;//updating the datasource of the custom dropdown
        this.dropDownListObject.refresh();//trying to refresh the dropdown object variable
      });
    }


//declaring the dropdown into the toolbar
documentEditorToolbarSettings = {
    enableFloating: true,
    items: [
      {
        tooltipText: 'Select placeholder value',
        template: '<input type="text" id="dropdown" />'
      }
    ]
  };
//HTML code of my rich text editor
 <ejs-richtexteditor id="customRTE" #customRTE formControlName="EmailBody" placeholder="" (open)="OnOpen()"
                                  [toolbarSettings]="this.documentEditorToolbarSettings" height="250"
                                  (created)="oncreated()">
              </ejs-richtexteditor>


//Hardcoded values for the custom dropdown which will be always visible with other dynamic fields
 placeHolderdata: { [key: string]: Object }[] = [
    { Value: 'url', FieldName: 'url' },
    { Value: 'userid', FieldName: 'userid' },
    { Value: 'username.loginemail', FieldName: 'username.loginemail' },
    { Value: 'emailotp', FieldName: 'emailotp' },
    { Value: 'emailotpvalidaity', FieldName: 'emailotpvalidaity' },
    { Value: 'password', FieldName: 'password' }
  ];




//defining the Created event of the rich text editor
public dropDownListObject: DropDownList
  oncreated(): void {
    // initialize DropDownList component
    this.dropDownListObject = new DropDownList({
      placeholder: "Select PlaceHolder Value",
      width: "300px",
      fields: { text: 'FieldName' },
      beforeOpen: this.OnChanged.bind(this),
      //set the data to dataSource property
      dataSource: this.placeHolderdata
    });
    // render initialized DropDownList
    this.dropDownListObject.appendTo('#dropdown');
}


Now I think you are getting my issue clearly. Please response for the same Thank you in advance





IS Indrajith Srinivasan Syncfusion Team July 29, 2020 01:19 PM UTC

Hi Rakhi,

Good day to you,

We have validated your reported query. Based on the reported query, we understood that the DropDownList’s data source is not updated (which is placed inside the Rich Text Editor) properly based on the selected items of DropDownList (which is placed outside of the editor). We have also prepared a sample by updating the data source dynamically for every value selected in the left side dropdown.

Sample: https://stackblitz.com/edit/angular-nvf4zk-k8h5vr?file=app.component.html

Can you please check the above sample and let us know if it meets your requirements, If not, can you replicate the issue in the above sample and revert back to us?
 
 
If we are able to reproduce the reported issue, we can validate and provide a solution at earliest.

Regards,
Indrajith
 



RA RakhiS July 30, 2020 01:31 AM UTC

Thanks Indrajith for your quick response.
But the sample you provided is using the same code instead on change event of dropdown I have used getEntities method in which I am getting fields dynamically and I am pushing(puasg it with hardcoded already existing values as defined in placeholder data below) it into the datasource of the custom dropdown, and used the same line of code oof   this.dropdownlistobject.datasource = this placeholderdata(which is filled up with the dynamically fields). This is the difference. I cannot replicate it in code as I am using dynamic values and you are using harcoding valing and in change event you can  check with args.value and alloting it into it. Please go through my code again also I have provided all comments to get much understanding on it.


Please help. Also if possible to have a call regarding this so that I can ask you and show you my requirement by running into my application.


IS Indrajith Srinivasan Syncfusion Team July 30, 2020 02:33 PM UTC

Hi Rakhi, 
 
We have modified the sample as per the requirement “When the parent dropdown changes, based on the selected vale the custom dropdown datasource will be refreshed and updated”. Please find the code snippet and sample below for reference. 
  
<h3>Parent Dropdown</h3 
          <ejs-dropdownlist #ddlelement2 id='ddlelement2' [dataSource]="countryData"[fields]="countryFields" (change)="countryChange()" placeholder = 'Select a game'></ejs-dropdownlist>  
  
   // initialize Custom DropDownList component  
   this.dropDownListObject = new DropDownList({  
    placeholder: "Select PlaceHolder Value" 
    width: "180px" 
    fields: { text: 'StateName', value: "SateId" },  
    //set the data to dataSource property  
    dataSource: this.placeHolderdata  
});  
this.dropDownListObject.appendTo('#ddlelement');  
 
//Parent dropdown change event  
public countryChange(): void  
let tempQuery: Query = new Query().where('CountryId', 'equal', this.countryObj.value);  
    this.dropDownListObject.query = tempQuery;  
      this.dropDownListObject.text = null;  
        this.dropDownListObject.dataBind();  
 
  
 
  
Kindly check with the above sample. Please get back us if you need further assistance.  
 
Regards,  
Indrajith 



RA RakhiS July 31, 2020 03:08 AM UTC

Thanks Indrajith, it is working but I want to display the hardcoded values with every different selection of parent dropdown. How can I merge into it. 
the placeholder dropdown data in code that I shared. I want to merge this data as well.


getEntities(value) {    
    this._stepcolservice.getAllEntities(this.EntityId)   
      .subscribe(result => {       
        this.dropDownListObject.dataSource = result;       
        let tempQuery: Query = new Query().where('EntityId', 'equal', value);
        this.dropDownListObject.query = tempQuery;
        this.dropDownListObject.text = null;
        this.dropDownListObject.dataBind(); //right now I have bind my dynamic data in this way
}

//this is my hardcoded data
 placeHolderdata: { [key: string]: Object }[] = [
    { Value: 'url', FieldName: 'url'},
    { Value: 'userid', FieldName: 'userid'},
    { Value: 'username.loginemail', FieldName: 'username.loginemail'},
    { Value: 'emailotp', FieldName: 'emailotp', EntityId:0  },
    { Value: 'emailotpvalidaity', FieldName: 'emailotpvalidaity' },
    { Value: 'password', FieldName: 'password' }
  ];


IS Indrajith Srinivasan Syncfusion Team July 31, 2020 02:14 PM UTC

Hi Rakhi, 
 
We have validated your reported query. For maintaining same datasource values on different selection, we suggest you to bind the datasource with the common field value and modify the query using predicate. For sample purpose, we used common field as 'CountryID'. 
 
public countryData: { [keystring]: Object }[] = [  
    { CountryName: 'Australia', CountryId: '2' },  
    { CountryName: 'United States', CountryId: '1' }  
];  
//define the state DropDownList data  
public placeHolderdata: { [keystring]: Object }[] = [  
    { StateName: 'US state -1', CountryId: '1', SateId: '101' },  
    { StateName: 'US state -2 ', CountryId: '1', SateId: '102' },  
    { StateName: 'Australia State -1 ', CountryId: '2', SateId: '105' },  
    { StateName: 'Australia State -2', CountryId: '2', SateId: '106' },  
    { StateName: 'US state -3 ', CountryId: '1', SateId: '108' },  
    { StateName: 'Australia State -3 ', CountryId: '2', SateId: '109' },  
    { StateName: 'url', SateId: 'url',CountryId: '0'},  
  { StateName: 'userid', SateId: 'userid',CountryId: '0'},  
  { StateName: 'username.loginemail', SateId: 'username.loginemail',CountryId: '0'},  
  { StateName: 'emailotp', SateId: 'emailotp', EntityId:0 ,CountryId: '0' },  
  { StateName: 'emailotpvalidaity', SateId: 'emailotpvalidaity',CountryId: '0' },  
  { StateName: 'password', SateId: 'password',CountryId: '0' }  
];  
 
 
Regards, 
Indrajith 



RA RakhiS August 5, 2020 08:10 AM UTC

Thank you so much   Indrajith, it is now working as expected.


IS Indrajith Srinivasan Syncfusion Team August 5, 2020 08:22 AM UTC

Hi Rakhi,

Welcome,

Please get back to us if you need any further assitance.

Regards,
Indrajith

Loader.
Up arrow icon