Advertisement
Igor150195

форма

Apr 7th, 2025
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. lpc_template.queue.refreshForm = function ($self) {
  2.  
  3.         console.log(33)
  4.  
  5.         const $refreshButton = $('.lpc-refresh-form');
  6.    
  7.         if (!$refreshButton.length) {
  8.             return;
  9.         }
  10.        
  11.    
  12.         const href = $refreshButton.attr('href');
  13.         const popupMatch = href?.match(/popup:_lp_block_(\d+)/);
  14.  
  15.        
  16.         console.log(popupMatch)
  17.         if (!popupMatch) {
  18.             return;
  19.         }
  20.  
  21.         console.log(href)
  22.    
  23.         const popupId = popupMatch[1];
  24.         const $popupElement = $(`[data-block-id="${popupId}"]`);
  25.    
  26.         if (!$popupElement.length) {
  27.             return;
  28.         }
  29.    
  30.         const $form = $popupElement.find('.lp-form-tpl');
  31.         if (!$form.length) {
  32.             console.log('❌ Форма не найдена внутри попапа');
  33.             return;
  34.         }
  35.    
  36.         const apiUrl = $form.attr('data-lpc-api-url');
  37.         console.log(apiUrl);
  38.    
  39.         $refreshButton.off('click.refreshForm');
  40.    
  41.         $refreshButton.on('click.refreshForm', function (e) {
  42.  
  43.             const $form2 = $popupElement.find('.lp-form-tpl');
  44.             // проверяешь есть ли успешно отправленнная форма, только потом тянешь аяксом форму, если уже отправляли форму, которая без аякса
  45.             e.preventDefault();
  46.                
  47.             console.log(5553)
  48.    
  49.             $.ajax({
  50.                 url: apiUrl,
  51.                 dataType: 'json',
  52.                 success: function (response) {
  53.                     if (!response.result.error) {
  54.                         let htmlForm = response.result.html;
  55.    
  56.                         $form2.replaceWith(htmlForm);
  57.    
  58.                         console.log(34343434)
  59.                         s3LP.initForms($('#_lp_block_372266709'));
  60.                     }
  61.                 }
  62.             });
  63.         });
  64.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement