Adding a Button to Change Text Color in ui.editor Toolbar #3575
-
QuestionHello everyone, I previously managed to add a save button to the toolbar in ui.editor with the help of the community (refer to the discussion here). Thanks to your guidance, the functionality works as expected. Now, I would like to take it a step further by adding a button to the toolbar that allows users to change the color of the selected text. Could anyone guide me on how to achieve this? Any advice or examples would be greatly appreciated! Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
You can run editor commands with the editor = ui.editor()
editor._props['toolbar'] = [
['left', 'center', 'right', 'justify'],
['bold', 'italic', 'underline', 'strike'],
['undo', 'redo'],
['red'],
]
with editor.add_slot('red'):
ui.button(icon='format_color_text',
on_click=lambda: editor.run_method('runCmd', 'foreColor', 'red')) \
.props('flat dense size=sm').classes('text-red') But I'm not sure if all browsers support such commands. Quasar just points to https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand, where it is marked as deprecated. Does anyone have more information about this API? |
Beta Was this translation helpful? Give feedback.
@falkoschindler Thank your method, I get the final solution.
Here is: