Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Slug generator
- *
- */
- const name = document.getElementById('name');
- const slug = document.getElementById('slug');
- if (name && slug) {
- // Init a timeout variable to be used below
- let timeout = null;
- // Bind keyup event
- name.onkeyup = function (e) {
- let self = this;
- // Clear the timeout if it has already been set.
- // This will prevent the previous task from executing
- // if it has been less than <MILLISECONDS>
- clearTimeout(timeout);
- // Make a new timeout set to go off in 300ms
- timeout = setTimeout(function (e) {
- getSlug(self.value);
- }, 300);
- };
- window.getSlug = (string) => {
- // Set form data
- let data = new FormData();
- data.append('string', string);
- // Make the call
- axios.post('/dashboard/products/createslug', data)
- .then(function (res) {
- slug.value = res.data;
- })
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement