Error-prone code accidentally started working, but then broke again when updating

I am trying to set the selectize-rails gem. I had a lot of problems ( TypeError: $ (...). Selectize is not a function ), so I refused for some time and worked on unrelated things. Then I returned to it, and the gem suddenly worked, although none of the code that I changed had anything to do with it. Then I changed one line of code and refreshed the page to see the result, and it again displayed the same error in the web console as before:

TypeError: $(...).selectize is not a function 

After that, this is literally all that I did: 1) clicked "back" in my text editor to return the change, 2) saved the document and 3) updated the page. And the error was still there, although the same code only worked a few seconds earlier.

Does anyone know how this is possible?

Here's a block of code that didn't work, then suddenly started working, and then stopped again:

 <script type="text/javascript"> $(document).ready(function() { console.log( typeof $.fn.selectize === 'function'); // true console.log( $('#select-to').length === 1 ); // true var REGEX_EMAIL = '([a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@' + '(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)'; $('#select-to').selectize({ persist: false, maxItems: null, valueField: 'email', labelField: 'name', searchField: ['name', 'email'], options: [ {email: ' brian@thirdroute.com ', name: 'Brian Reavis'}, {email: ' nikola@tesla.com ', name: 'Nikola Tesla'}, {email: ' someone@gmail.com '} ], render: { item: function(item, escape) { return '<div>' + (item.name ? '<span class="name">' + escape(item.name) + '</span>' : '') + (item.email ? '<span class="email">' + escape(item.email) + '</span>' : '') + '</div>'; }, option: function(item, escape) { var label = item.name || item.email; var caption = item.name ? item.email : null; return '<div>' + '<span class="label">' + escape(label) + '</span>' + (caption ? '<span class="caption">' + escape(caption) + '</span>' : '') + '</div>'; } }, createFilter: function(input) { var match, regex; // email@address.com regex = new RegExp('^' + REGEX_EMAIL + '$', 'i'); match = input.match(regex); if (match) return !this.options.hasOwnProperty(match[0]); // name < email@address.com > regex = new RegExp('^([^<]*)\<' + REGEX_EMAIL + '\>$', 'i'); match = input.match(regex); if (match) return !this.options.hasOwnProperty(match[2]); return false; }, create: function(input) { if ((new RegExp('^' + REGEX_EMAIL + '$', 'i')).test(input)) { return {email: input}; } var match = input.match(new RegExp('^([^<]*)\<' + REGEX_EMAIL + '\>$', 'i')); if (match) { return { email : match[2], name : $.trim(match[1]) }; } alert('Invalid email address.'); return false; } }); }); </script> 

I changed this line:

 {email: ' someone@gmail.com '} 

:

 {email: '<%= link_to "home", root_path %>'} 

and then back.

0
source share

Source: https://habr.com/ru/post/1210323/


All Articles