23. Làm name trường input động (ok)

C:\xampp\htdocs\test\wp-content\plugins\plugin-name\admin\js\wpf-themplate_ct.js

Unique: function($module) {
      $module.each(function() {
        var $m = $(this);
        var $labels = $m.find('label');
        $labels.each(function() {
          var $id = $(this).attr('for');
          if ($id) {
            $id = WPF.Escape($(this).attr('for'));
            if ($('#' + $id).length > 0) {
              var $uniqud = WPF.GenerateUnique();
              $m.find('#' + $id).attr('id', $uniqud);
              $(this).attr('for', $uniqud);
            }
          }
        });
        var $reg = /.*?\[(.+?)\]/ig;
        var $input = $m.find('input[type="radio"]');
        var $radios = {};
        $input.each(function($i) {
          var $name = $(this).attr('name');
          if ($name) {
            $radios[$name] = 1;
          }
        });
        for (var $name in $radios) {
          var $match = $name.match($reg);
          if ($match) {
            var $uniqeuname = WPF.GenerateUnique();
            var $radio = $m.find('input:radio[name="' + $name + '"]'); //if there are several groups radio
            var $new_name = $uniqeuname + $match[0] + $match[1];
            $radio.attr('name', $new_name);
            if ($m.find('input:radio[name!="' + $name + '"]')) { //if empty
              $m.find('input:radio[name="' + $new_name + '"][checked]').prop('checked', true); //to display checked;
            }
          }
        }
      });
    },
    GenerateUnique: function() {
      return WPF.prefix + Math.random().toString(36).substr(2, 9);
    },
    Escape: function($selector) {
      return $selector.replace(/(:|\.|\[|\]|,)/g, "\\$1");
    }

Last updated