givanz / VvvebJs

Drag and drop page builder library written in vanilla javascript without dependencies or build tools.
https://www.vvveb.com/vvvebjs/editor.html
Apache License 2.0
6.91k stars 1.59k forks source link

'Link to' for button and 'URL' for anchor tag are redirecting to 'baseurl of the page + the entered url' in Frontend #268

Open Darpan-laravel opened 1 year ago

Darpan-laravel commented 1 year ago

Hi Givanz, thanks for this amazing builder. There is one issue that I am facing in this builder. When I add 'Link ' to a button or 'url' to an anchor tag and save it, it is redirecting me to 'baseurl of the page + the entered url' in the frontend. For example, if I enter 'www.google.com' in the url of an anchor tag and the path to the page in frontend is 'http://localhost/my-page/', then it is redirecting me to 'http://localhost/my-page/'www.google.com'. Which should have been to only 'www.google.com'.

Can you please help me to solve this?

givanz commented 1 year ago

Hi

Thank you, this happens because the url does not have // and the browsers considers it a relative path to current domain, if you use for example //www.google.com or https://www.google.com it will work.

You can add some code to detect www. and add the missing 'https://' automatically by editing the LinkInput code at https://github.com/givanz/VvvebJs/blob/master/libs/builder/inputs.js#L233

var LinkInput = $.extend({}, TextInput, {

    events: [
        ["change", "onChange", "input"],
     ],

    setValue: function(value) {
        value = value.replace(/(?<!\/)www\./, 'https://www.');
        $('input', this.element).val(value);
    },

    init: function(data) {
        return this.render("textinput", data);
    },
  }
);