Problem with code widget bric

Hello
I would like to insert a widget in a page of my site and I use the widget code bric. I copy and paste the following lines into it

<div class="box">
    <style>
        .widget {
            background: #5ba4d4;
            padding-top: 30px;
            padding-bottom: 30px;
            padding-right: 30px;
            padding-left: 20px;
            width: 300px;
            border-radius: 2px;
        }

        .widget input {
            padding: 5px;
            border-radius: 2px;
            border: none;
            margin: 4px;
            width: 100%;
        }

        .check-availability {
            border: 2px solid white !important;
            background-color: transparent;
            color: white;
            font-weight: 600;
        }

        .datepicker-top-left, .datepicker-top-right{
            transition: none;
        }
    </style>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.6.4/datepicker.min.js"></script>
    <link  href="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.6.4/datepicker.min.css" rel="stylesheet">

    <div class="widget">
        <form target="_blank" action="https://portal.freetobook.com/reservations">
            <input type="hidden" name="w_id" value="[YOUR_WIDGET_ID_HERE]">
            <input type="hidden" name="w_tkn" value="[YOUR_WIDGET_TOKEN_HERE]">
            <input type="hidden" id="check-in-date-to-send" name="check_in_date">
            <input type="hidden" id="check-out-date-to-send" name="check_out_date">
            <b class="arrival-text">Arrival</b><br/>
            <input id="check-in-date" data-toggle="datepicker" placeholder="Please select arrival date">
            <b class="departure-text">Departure</b><br/>
            <input id="check-out-date" data-toggle="datepicker" placeholder="Please select departure date">
            <input id="stay-length" type="hidden" name="stay_length" value="1">
            <br/>
            <br/>
            <input type="submit" class="check-availability" value="Check Availability">
        </form>
    </div>
    <script>
        var $checkInDatePicker = $('#check-in-date');
        var $checkOutDatePicker = $('#check-out-date');

        $checkInDatePicker.datepicker({
            format: 'dd-mm-yyyy',
            autoHide: true,
            autoPick: true
        });

        var initialCheckInDate = $checkInDatePicker.datepicker('getDate');
        var initialCheckOutDate = addDays(initialCheckInDate, 1);

        $checkOutDatePicker.datepicker({
            format: 'dd-mm-yyyy',
            autoPick: true,
            date: initialCheckOutDate
        });

        $checkInDatePicker.on('change', function() {
            var checkInDate = $checkInDatePicker.datepicker('getDate');
            var checkOutDate = addDays(checkInDate, 1);
            $checkOutDatePicker.datepicker('setDate', checkOutDate);

            updateDatesToSend(checkInDate, checkOutDate);
            updateStayLength();
        });

        $checkOutDatePicker.on('change', function() {
            updateStayLength();
        });

        updateDatesToSend(initialCheckInDate, initialCheckOutDate);

        function addDays(date, days) {
            var result = new Date(date);
            result.setDate(result.getDate() + days);
            return result;
        }

        function updateStayLength() {
            var date1 = $checkInDatePicker.datepicker('getDate');
            var date2 = $checkOutDatePicker.datepicker('getDate');

            var difference = daysBetween(date1, date2);
            if ( difference < 1 ) difference = 1;
            $("#stay-length").val(difference);
        }

        function updateDatesToSend(checkInDate, checkOutDate) {
            var dd0 = checkInDate.getDate();
            var mm0 = checkInDate.getMonth() + 1;
            var yyyy0 = checkInDate.getFullYear();
            if ( dd0 < 10 ) dd0 = '0' + dd0;
            if ( mm0 < 10 ) mm0 = '0' + mm0;
            $("#check-in-date-to-send").val(yyyy0 + '-' + mm0 + '-' + dd0);

            var dd = checkOutDate.getDate();
            var mm = checkOutDate.getMonth() + 1;
            var yyyy = checkOutDate.getFullYear();
            if ( dd < 10 ) dd = '0' + dd;
            if ( mm < 10 ) mm = '0' + mm;
            $("#check-out-date-to-send").val(yyyy + '-' + mm + '-' + dd);
        }

        function daysBetween( date1, date2 ) {
            var one_day=1000*60*60*24;
            var date1_ms = date1.getTime();
            var date2_ms = date2.getTime();
            var difference_ms = date2_ms - date1_ms;
            return Math.round(difference_ms/one_day);
        }
    </script>
</div>

I encounter the following problem: the widget doesn’t work well because it’s supposed to make date pickers appear, but especially when I go back into code widget bric, blocs automatically added lines and transforms the “<” into “&lt”.

Is this a bug?

Thanks for your help

Capture d’écran 2021-02-04 à 10.56.25

Run your code through a text editor first (i. e. CotEditor >> you can get it for free in Mac App Store) to get rid of the text formatting and then insert the code in the widget bric.
Cheers,

It’s done, but I still have the same problem.
Thank you

Did you use the original code for the CotEditor? CotEditor will not revers the HTML format to plain text when you insert them to it.

Which version of Blocs are you using? I’m not able to replicate this issue when exporting. You can inspect it here: http://toukorek.com/blocs/calendar/index.html

I use blocs 4.04

yes i use the original’s code by copy and paste

This seems to be a Blocs problem because I copied the same code to another website editor and it works without any problem.
Any ideas?

Download Blocs 4.1 b4 and see if the issue remains the same. On both of my machines (intel and M1) it exports correctly for me.

It’s exactly the same : Erreur 404 - Le Moulin du Boisset, Maison d'hôtes de charme

and the test with another website editor : Erreur 404 - Le Moulin du Boisset, Maison d'hôtes de charme

Have you applied any classes to the bloc/code widget, or did you add a code manually to your file? Please PM me the file and I’ll have a look.

You’ll need to add the script tags to your project through differently.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.6.4/datepicker.min.js"></script>
<link  href="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.6.4/datepicker.min.css" rel="stylesheet">

The first script is jquery which is not needed because Blocs will load it, remove that.
The next script is the datapicker javascript. we want to ensure it loads after jquery, so place that line in the Footer of the Code Editor.

The last line (Stylesheet) goes in the Header although it should still work anywhere on the page. This will ensure there’s no sudden flash of un-styled elements.

Finally, place the last script tag in your code AFTER the datapicker script. So in the Footer you’ll have the following script tags in order:

<script src="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.6.4/datepicker.min.js"></script>
<script>
        var $checkInDatePicker = $('#check-in-date');
        var $checkOutDatePicker = $('#check-out-date');

        $checkInDatePicker.datepicker({
            format: 'dd-mm-yyyy',
            autoHide: true,
            autoPick: true
        });

        var initialCheckInDate = $checkInDatePicker.datepicker('getDate');
        var initialCheckOutDate = addDays(initialCheckInDate, 1);

        $checkOutDatePicker.datepicker({
            format: 'dd-mm-yyyy',
            autoPick: true,
            date: initialCheckOutDate
        });

        $checkInDatePicker.on('change', function() {
            var checkInDate = $checkInDatePicker.datepicker('getDate');
            var checkOutDate = addDays(checkInDate, 1);
            $checkOutDatePicker.datepicker('setDate', checkOutDate);

            updateDatesToSend(checkInDate, checkOutDate);
            updateStayLength();
        });

        $checkOutDatePicker.on('change', function() {
            updateStayLength();
        });

        updateDatesToSend(initialCheckInDate, initialCheckOutDate);

        function addDays(date, days) {
            var result = new Date(date);
            result.setDate(result.getDate() + days);
            return result;
        }

        function updateStayLength() {
            var date1 = $checkInDatePicker.datepicker('getDate');
            var date2 = $checkOutDatePicker.datepicker('getDate');

            var difference = daysBetween(date1, date2);
            if ( difference < 1 ) difference = 1;
            $("#stay-length").val(difference);
        }

        function updateDatesToSend(checkInDate, checkOutDate) {
            var dd0 = checkInDate.getDate();
            var mm0 = checkInDate.getMonth() + 1;
            var yyyy0 = checkInDate.getFullYear();
            if ( dd0 < 10 ) dd0 = '0' + dd0;
            if ( mm0 < 10 ) mm0 = '0' + mm0;
            $("#check-in-date-to-send").val(yyyy0 + '-' + mm0 + '-' + dd0);

            var dd = checkOutDate.getDate();
            var mm = checkOutDate.getMonth() + 1;
            var yyyy = checkOutDate.getFullYear();
            if ( dd < 10 ) dd = '0' + dd;
            if ( mm < 10 ) mm = '0' + mm;
            $("#check-out-date-to-send").val(yyyy + '-' + mm + '-' + dd);
        }

        function daysBetween( date1, date2 ) {
            var one_day=1000*60*60*24;
            var date1_ms = date1.getTime();
            var date2_ms = date2.getTime();
            var difference_ms = date2_ms - date1_ms;
            return Math.round(difference_ms/one_day);
        }
    </script>

3 Likes

Hello @Pat yes you’r right this is an “OOOOOLLLLLLDDDDDD” bug and I have it a lot of times as well, the only thing you need to do is copy all your code, then delete it, close the code editor, unselect the “preview content” under the “Edit Code” button, and with that option unselected, open the code editor and paste your code.
Then when you preview everithing is working, but with that “preview content” unselected.

Check here:

Hope @Norm could fix it, I have this issues today as well…

1 Like

Thank you very much for your help. It works very well.