Месяц: Октябрь 2016

Select2. Изменение поля при выборе значения.

Задача состоит в следующем: при выборе номера телефона клиента необходимо в другом поле изменять значение.

 

HTML:

<form action="" name="record">
  <select class="form-control select2" name="client-phone" data-placeholder="Телефон" style="width: 100%;" tabindex="-1" aria-hidden="true">
    <option value=""></option>
    <option value="1">+7 (555) 555-5555</option>
    <option value="2">+7 (651) 651-6516</option>
    <option value="3">+7 (516) 565-1651</option>
  </select>
  <p>или ФИО</p>
  <select class="form-control select2" name="client" data-placeholder="ФИО" style="width: 100%;" tabindex="-1" aria-hidden="true">
    <option value=""></option>
    <option value="1">ФИО 1</option>
    <option value="2">ФИО 2</option>
    <option value="3">ФИО 3</option>
  </select>
</form>

 

JS:

$('form[name="record"] [name=client-phone]').on('select2:select', function(evt) {
  selectClient('client', evt.params.data.id);
});

$('form[name="record"] [name=client]').on('select2:select', function(evt) {
  selectClient('client-phone', evt.params.data.id);
});

function selectClient(name, id) {
  $('form[name="record"] [name="' + name + '"]').select2('val', id);
}
$(".select2").select2();

 


 

В функцию selectClient передаем имя поля которое необходимо изменить и id выбранного значения.

Результат:

https://jsfiddle.net/yqhaw8fd/

XAMPP. Ошибка при включении Apache.

11:42:21  [main]  Initializing Control Panel
11:42:21  [main]  Windows Version:  Pro  64-bit
11:42:21  [main]  XAMPP Version: 5.6.21
11:42:21  [main]  Control Panel Version: 3.2.2  [ Compiled: Nov 12th 2015 ]
11:42:21  [main]  You are not running with administrator rights! This will work for
11:42:21  [main]  most application stuff but whenever you do something with services
11:42:21  [main]  there will be a security dialogue or things will break! So think
11:42:21  [main]  about running this application with administrator rights!
11:42:21  [main]  XAMPP Installation Directory: «c:\xampp\»
11:42:21  [main]  Checking for prerequisites
11:42:22  [main]  All prerequisites found
11:42:22  [main]  Initializing Modules
11:42:22  [Apache]  Problem detected!
11:42:22  [Apache]  Port 80 in use by «Unable to open process» with PID 4!
11:42:22  [Apache]  Apache WILL NOT start without the configured ports free!
11:42:22  [Apache]  You need to uninstall/disable/reconfigure the blocking application
11:42:22  [Apache]  or reconfigure Apache and the Control Panel to listen on a different port
11:42:22  [main]  Enabling autostart for module «Apache»
11:42:22  [main]  Enabling autostart for module «MySQL»
11:42:22  [main]  Enabling autostart for module «Mercury»
11:42:22  [main]  Starting Check-Timer
11:42:22  [main]  Control Panel Ready
11:42:22  [Apache]  Autostart active: starting…
11:42:22  [Apache]  Problem detected!
11:42:22  [Apache]  Port 80 in use by «Unable to open process» with PID 4!
11:42:22  [Apache]  Apache WILL NOT start without the configured ports free!
11:42:22  [Apache]  You need to uninstall/disable/reconfigure the blocking application
11:42:22  [Apache]  or reconfigure Apache and the Control Panel to listen on a different port
11:42:22  [Apache]  Attempting to start Apache app…
11:42:23  [mysql]  Autostart active: starting…
11:42:23  [mysql]  Attempting to start MySQL app…
11:42:24  [mercury]  Autostart active: starting…
11:42:24  [mercury]  Attempting to start Mercury app…
11:42:24  [Apache]  Status change detected: running
11:42:24  [mysql]  Status change detected: running
11:42:24  [mercury]  Status change detected: running
11:42:27  [Apache]  Status change detected: stopped
11:42:27  [Apache]  Error: Apache shutdown unexpectedly.
11:42:27  [Apache]  This may be due to a blocked port, missing dependencies,
11:42:27  [Apache]  improper privileges, a crash, or a shutdown by another method.
11:42:27  [Apache]  Press the Logs button to view error logs and check
11:42:27  [Apache]  the Windows Event Viewer for more clues
11:42:27  [Apache]  If you need more help, copy and post this
11:42:27  [Apache]  entire log window on the forums

 

Проблема из-за того что 80 порт занят.

Решение открыть командную строку от администратора и ввести команду:

net stop http

это остановит приложения с портом 80.

Запоминание позиций jQuery UI Sortable

Структура html

<div class="row" id="sortBlock">
       <section class="col-md-4 connectedSortable">
           // содержимое секции
       </section>
       <section class="col-md-4 connectedSortable">
           // содержимое секции           
       </section>
       <section class="col-md-4 connectedSortable">
           // содержимое секции
       </section>
       <section class="col-md-4 connectedSortable">
           // содержимое секции
       </section>
       <section class="col-md-4 connectedSortable">
           // содержимое секции
       </section>
       <section class="col-md-4 connectedSortable">
          // содержимое секции
       </section>
   </div>

 

 

<script> 
   $(".connectedSortable .box-header, .connectedSortable .nav-tabs-custom").css("cursor", "move");
    var root = $('#sortBlock');
    var pathname = window.location.pathname;
    var c = cookies.get(pathname);

    $('> *', root).each(function (index) {
        this.id = 'item-' + index;
    });

    root.sortable({
//        placeholder: "sort-highlight",
        connectWith: ".connectedSortable",
        handle: ".box-header, .nav-tabs",
        forcePlaceholderSize: true,
        'update': function (event, ui) {
            var order = $(this).sortable('serialize');
            cookies.set(pathname, {pathname, order});
        }
    });

    if (c) {
        $.each(c.order.split('&'), function () {
            var id = this.replace('[]=', '-');
            $('#' + id).appendTo(root);
        });
    }
</script>

 

Для использования кук был использован плагин.

Первосточник: Хранитель заметок