Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm trying to define a markdown link button with the next way
js:
var selection = E.getSelection();
var match = selection.match(/\[([^\]]*)\]\(([^\)]*)\)/) || selection.match(/(.*)\s((?:http|https|ftp|ftps):\/\/\S*)/) || selection.match(/(.*)()/) || ['', '', ''];
var fields = [
{ name: 'url', title: 'URL', required: true, value: match[2] || '' },
{ name: 'text', title: 'Text', required: true, value: value = match[1] || '' }
];
function submitHandler(tag, form, E) {
E.replaceSelection('[' + tag.attributes.text + '](' + tag.attributes.url + ')');
};
E.tagDialog('custom_markdown_link', fields, {title: 'Insert link', submit: submitHandler});
So the form values are formed by the selection.
It works correctly for the firls button click.
But when the button is clicked the second time the dialog values are the same as for the first time even if the selection was changed.
The workaround is adding the following two lines:
document.getElementById('bue-field-1').value = match[2] || '';
document.getElementById('bue-field-2').value = match[1] || '';
Comments
Comment #3
ufku CreditAttribution: ufku commentedFixed in dev branch. Thanks for reporting.
FYI, you can access the form elements by their name:
Comment #4
ufku CreditAttribution: ufku commented