| Предыдущая версия справа и слеваПредыдущая версия | |
| ajaxform_onkoweb_medrf [2025/11/06 14:21] – внешнее изменение 127.0.0.1 | ajaxform_onkoweb_medrf [2026/08/17 16:00] (текущий) – удалено bonterkoz |
|---|
| Проверка заполнения полей формы AJAX | |
| |
| <code> | |
| |
| |
| $(function(){ | |
| | |
| //Фамилия с большой буквы | |
| $('input[name="new_patient_surname"]').keyup(function(evt){ | |
| var txt = $(this).val(); | |
| // Regex taken from php.js (http://phpjs.org/functions/ucwords:569) | |
| $(this).val(txt.replace(/^(.)|\s(.)/g, function($1){ return $1.toUpperCase( ); })); | |
| }); | |
| |
| //Имя с большой буквы | |
| $('input[name="new_patient_firstname"]').keyup(function(evt){ | |
| var txt = $(this).val(); | |
| // Regex taken from php.js (http://phpjs.org/functions/ucwords:569) | |
| $(this).val(txt.replace(/^(.)|\s(.)/g, function($1){ return $1.toUpperCase( ); })); | |
| }); | |
| | |
| //Отчество с большой буквы | |
| $('input[name="new_patient_middlename"]').keyup(function(evt){ | |
| var txt = $(this).val(); | |
| // Regex taken from php.js (http://phpjs.org/functions/ucwords:569) | |
| $(this).val(txt.replace(/^(.)|\s(.)/g, function($1){ return $1.toUpperCase( ); })); | |
| }); | |
| | |
| | |
| $('#shs_jqGrid_table').jqGrid({ | |
| url:'index.php', // Скрипт - обработчик ваших запросов | |
| //postData: $("#myForm").serialize(), | |
| datatype: 'json', | |
| mtype: 'POST', | |
| postData:{"action": "report_ajax"}, | |
| colNames:['Обзвон','Дата направления', 'Пациент', 'Врач','ЛПУ', '№','Диагноз','Консультация','КТ','МРТ'], | |
| colModel :[ | |
| |
| {name:'obzvon_001', index:'obzvon_001', width: 52, | |
| editable: true, | |
| edittype: 'checkbox', editoptions: { value: "True:False" }, | |
| formatter: "checkbox", formatoptions: { disabled: true} | |
| }, | |
| /* | |
| {name:'obzvon_001', index:'obzvon_001', width: 24} | |
| */ | |
| |
| {name:'date_napravleniya', index:'date_napravleniya', width:137}, | |
| {name:'fio', index:'fio_patient', width:224}, | |
| {name:'doctor', index:'doctor', width:222}, | |
| {name:'lpu', index:'lpu', width:196}, | |
| {name:'number', index:'number', width:32}, | |
| {name:'diagnoz', index:'diagnoz', width:110}, | |
| {name:'konsultaciya', index:'konsultaciya_info', width:110}, | |
| {name:'kt_info', index:'kt_info', width:110}, | |
| {name:'mrt_info', index:'mrt_info', width:110}, | |
| | |
| ], | |
| pager: $('#shs_jdGrid_Paginate'), | |
| rowNum:10, /*эта опция больше 10 глючит (пропадают\неотображаются пациенты)*/ | |
| height: '100%', | |
| rowList:[10,30,100], | |
| sortname: 'date_napravleniya', | |
| sortorder: 'DESC', | |
| onSelectRow: function(id){ | |
| var url = 'index.php?p_uid='+id+'&action=show_patient'; | |
| window.open(url); | |
| }, | |
| /* | |
| loadComplete: function() { | |
| |
| var rowIDs = jQuery("#shs_jqGrid_table").getDataIDs(); | |
| for (var i=0;i<rowIDs.length;i=i+1){ | |
| rowData=jQuery("#shs_jqGrid_table").getRowData(rowIDs[i]); | |
| var trElement = jQuery("#"+ rowIDs[i],jQuery('#shs_jqGrid_table')); | |
| if (rowData.obzvon_001 > 0) { | |
| trElement.removeClass('ui-widget-content'); | |
| trElement.addClass('rowColorGREEN'); | |
| }else{ | |
| if (rowData.obzvon_001 == ''){ | |
| trElement.removeClass('ui-widget-content'); | |
| trElement.addClass('rowColorRED'); | |
| } | |
| } | |
| } | |
| } | |
| */ | |
| loadComplete: function() { | |
| |
| var checkboxFix = []; | |
| $("#shs_jqGrid_table td[aria-describedby='obzvon_001'] input").each(function () { | |
| checkboxFix.push($(this).prop('checked')); | |
| }); | |
| }, | |
| /* | |
| afterInsertRow : function(rowId, rowData) | |
| { | |
| var rowData = $('#shs_jqGrid_table').jqGrid('getRowData', rowId); | |
| rowData.obzvon_001 = '12321'; | |
| $('#shs_jqGrid_table').jqGrid('setRowData', rowId, rowData); | |
| } | |
| */ | |
| |
| |
| afterInsertRow: function(row_id, row_data) { | |
| |
| var str = row_data.obzvon_001; | |
| |
| if (str == null) { | |
| var n = ''; | |
| } | |
| else { | |
| var n = str.length; | |
| |
| } | |
| /* | |
| Почему-то работает, хз почему. Добавляет недостающие галочки. | |
| */ | |
| if (n > 0) { | |
| //$(this).attr('checked',!($(this).attr('checked'))); | |
| //$('#shs_jqGrid_table').jqGrid('setCell', row_id, 'obzvon_001', '', {'background': 'green'}); | |
| $('#shs_jqGrid_table').jqGrid('setCell', row_id, 'obzvon_001', ' '); | |
| }else if (n == ''){ | |
| //$(this).attr('checked',!($(this).attr('checked'))); | |
| //$(this).attr('checked',!($(this).attr('checked'))); | |
| //$('#shs_jqGrid_table').jqGrid('setCell', row_id, 'obzvon_001', '', {'background': 'red'}); | |
| } | |
| } | |
| |
| }); | |
| |
| $("button[id='jqgrid_btn']").click(function(){ | |
| var stat_vrach_only = $("select[name='stat_vrach_only']").val(); | |
| var stat_vrach = $("input[name='stat_vrach']").val(); | |
| var stat_diagnoz_mkb10 = $("input[name='stat_diagnoz_mkb10']").val(); | |
| var stat_lpu = $("select[name='stat_lpu']").val(); | |
| var stat_date = $("input[name='reservation']").val(); | |
| | |
| | |
| $('#shs_jqGrid_table').jqGrid('setGridParam',{url:"index.php", page:1, postData:{"action":"report_ajax", "doctor_mask":stat_vrach, "doctor_mask1":stat_vrach_only, "diagnoz_mask":stat_diagnoz_mkb10, "lpu_mask":stat_lpu, "date_mask":stat_date}}).trigger("reloadGrid"); | |
| //$('#shs_jqGrid_table').jqGrid('setGridParam',{url:encodeURI("index.php?action=report_ajax&doctor_mask="+stat_vrach+"&diagnoz_mask="+stat_diagnoz_mkb10+"&lpu_mask="+stat_lpu+"&date_mask="+stat_date), page:1}).trigger("reloadGrid"); | |
| }); | |
| | |
| //DataTables | |
| /* | |
| var oTable = $('#example').dataTable( { | |
| "oLanguage": { | |
| "sUrl": "http://amd123.ru/clinic/js/datatables/examples/ajax/sources/dataTables.rus.txt" | |
| }, | |
| | |
| "bProcessing": true, | |
| "sAjaxSource": "http://amd123.ru/clinic/js/datatables/examples/ajax/sources/arrays.txt", | |
| | |
| //"sDom": '<"top"iflp<"clear">>rt<"bottom"iflp<"clear">>', | |
| | |
| //"sPaginationType": "full_numbers", | |
| //"sScrollY": 200, | |
| | |
| } ); | |
| | |
| */ | |
| $('#reservationtime').daterangepicker({ | |
| //timePicker: false, | |
| //timePickerIncrement: 30, | |
| format: 'DD-MM-YYYY', | |
| locale: { | |
| applyLabel: 'Ok', | |
| fromLabel: 'С', | |
| toLabel: 'ПО', | |
| customRangeLabel: 'Custom Range', | |
| daysOfWeek: ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт','Сб'], | |
| monthNames: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'], | |
| firstDay: 1 | |
| } | |
| | |
| | |
| }); | |
| | |
| | |
| |
| $('#search_patient .typeahead').typeahead({ | |
| name: "p-uid", | |
| remote: { | |
| url: 'index.php', | |
| /* | |
| replace: function () { | |
| var q = 'index.php?action=typeahead&query='; | |
| if ($('.typeahead').val()) { | |
| q += encodeURIComponent($('.typeahead').val()); | |
| } | |
| return q; | |
| }, | |
| */ | |
| replace: function (url, uriEncodedQuery){ | |
| return url + "#" + uriEncodedQuery; | |
| }, | |
| beforeSend: function (jqXhr, settings){ | |
| jqXhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); | |
| settings.type = 'POST'; | |
| settings.hasContent = true; | |
| settings.data = $.param({query: $('.typeahead').val(), action: "typeahead"}); | |
| } | |
| }, | |
| cache: false, | |
| limit: 20, | |
| allowDuplicates: true, | |
| valueKey: "name", | |
| template: '<p class="tt-p_custom"><strong>{{name}}</strong> <span>({{year}} г.р.)</span></p>', | |
| engine: Hogan | |
| }).on("typeahead:selected typeahead:autocompleted", | |
| function(e, datum) { | |
| $("#p_uid").val(datum.uid); | |
| } | |
| ); | |
| |
| $("button[name='new_patient_button_next']").click(function(){ | |
| myFunction(); | |
| $('.nav-tabs > .active').next('li').find('a').trigger('click'); | |
| | |
| /* | |
| var result = myFunction(); | |
| // если поле с мобильным телефоном заполнено | |
| if(result == true) { | |
| $("button[name='new_patient_button_next']").removeClass('disabled'); | |
| $('.nav-tabs > .active').next('li').find('a').trigger('click'); | |
| } | |
| if(result == false) { | |
| $('#new_patient_tab a:first').tab('show'); | |
| } | |
| else { | |
| $("button[name='new_patient_button_next']").css({"border":"1px solid green", "color":"green"}); | |
| //$('.nav-tabs > .active').next('li').find('a').trigger('click'); | |
| //$("button[name='new_patient_button_next']").addClass('disabled'); | |
| } | |
| */ | |
| }); | |
| | |
| | |
| function myFunction_block_tab (){ | |
| // Проверка заполнения поля "Мобильный тел." после загрузки документа | |
| $('#new_patient_tab a:first').tab('show'); | |
| // | |
| | |
| // Берем значение поля «Ваш номер телефона» | |
| var phoneV = $('input[name=new_patient_phone_mobile]').val(); | |
| // Определяем длину значения поля | |
| var phoneLngth = phoneV.length; | |
| if (phoneLngth != 18) { | |
| //$('#new_patient_tab li:eq(2) a').tab('show') // Select third tab (0-indexed) | |
| $('#new_patient_tab li:eq(1) a').removeAttr("data-toggle"); | |
| $('#new_patient_tab li:eq(2) a').removeAttr("data-toggle"); | |
| } | |
| else { | |
| $('#new_patient_tab li:eq(1) a').attr("data-toggle","tab"); | |
| $('#new_patient_tab li:eq(2) a').attr("data-toggle","tab"); | |
| } | |
| }; | |
| | |
| //проверяем существование элемента, запускаем проверку заполненности поля "Мобильный тел." | |
| var $resForm = $('input[name=new_patient_phone_mobile]'); | |
| if ($resForm.length > 0) { | |
| myFunction_block_tab(); | |
| } else { | |
| // Нет, такого элемента у нас нет. | |
| }; | |
| | |
| | |
| // Функция, может срабатывать по событию .hover и т.д | |
| function myFunction(){ | |
| // Убираем все классы с поля «Ваш номер телефона» | |
| | |
| $('input[name=new_patient_phone_mobile]').removeClass(); | |
| // Берем значение поля «Ваш номер телефона» | |
| var phoneV = $('input[name=new_patient_phone_mobile]').val(); | |
| // Определяем длину значения поля | |
| var phoneLngth = phoneV.length; | |
| if (phoneLngth <= 17) { | |
| // Проверяем чтобы длина номера телефона была не менее 18 символов | |
| // *********************************************************** | |
| // Здесь мы пишем что должно быть, если ввод НЕ корректен | |
| // *********************************************************** | |
| | |
| // Удаляем атрибут data-toggle, делаем НЕ активными вкладки "Предварительное лечение", "Диагноз" | |
| // Блокируем нажатие на кнопку "Далее" | |
| $('#new_patient_tab li:eq(1) a').removeAttr("data-toggle"); | |
| $('#new_patient_tab li:eq(2) a').removeAttr("data-toggle"); | |
| | |
| $('input[name=new_patient_phone_mobile]').css({"border":"1px solid red", "color":"red"}) | |
| // отфильтровать span'ы, оставив только те, которые лежат внутри параграфов | |
| var $spans = $('.error'); | |
| $("div.form-group").find( $spans ).text('Пожалуйста, введите номер телефона'); | |
| //$(this).next(".error").text('Введите пожалуйста ваш номер телефона'); | |
| } else { | |
| // ******************************************************* | |
| // Здесь мы пишем что должно быть, если все введено верно | |
| // ******************************************************* | |
| $("button[name='new_patient_button_next']").removeClass('disabled'); | |
| //myFunction_block_tab(); | |
| //$('input[name=new_patient_phone_mobile]').addClass('valid'); | |
| $('input[name=new_patient_phone_mobile]').css({"border":"1px solid green", "color":"green"}) | |
| var $spans = $('.error'); | |
| //$("div.form-group").find( $spans ).css('color','green'); | |
| $("div.form-group").find( $spans ).text(''); | |
| //$(this).next().text(''); | |
| // добавляем атрибуты вкладкам, делающих их активными | |
| // this.setAttribute("data-toggle","tab"); | |
| //$(this).attr("data-toggle","tab"); | |
| $('#new_patient_tab li:eq(1) a').attr("data-toggle","tab"); | |
| $('#new_patient_tab li:eq(2) a').attr("data-toggle","tab"); | |
| } | |
| }; | |
| | |
| |
| //$('input[name=new_patient_phone_mobile]').keyup(); | |
| |
| $('input[name=new_patient_phone_mobile]').on('blur', myFunction); | |
| $('input[name=new_patient_phone_mobile]').on('click', myFunction); | |
| $('input[name=new_patient_phone_mobile]').on('keyup', myFunction); | |
| | |
| $("button[name='new_patient_button_prev']").click(function(){ | |
| $('.nav-tabs > .active').prev('li').find('a').trigger('click'); | |
| }); | |
| |
| |
| $("input:radio[name='new_patient_pred_lech_radio']").change(function() { | |
| if (this.value == "yes") { | |
| $('#new_patient_pred_lech').prop('disabled', false); | |
| $('#new_patient_pred_lech_cont').show(300); | |
| } | |
| else { | |
| $('#new_patient_pred_lech').val(''); | |
| $('#new_patient_pred_lech').prop('disabled', true); | |
| $('#new_patient_pred_lech_cont').hide(300); | |
| } | |
| }); | |
| /* | |
| $("select[name='new_napravlenie_sel']").change(function() { | |
| if (this.value != "3") { | |
| $('[id^="new_napravlenie_fg_"]').show(300); | |
| } | |
| else { | |
| $('[id^="new_napravlenie_fg_"]').hide(300); | |
| $("input:checkbox[name^=new_napravlenie_]").prop('checked', false); | |
| $('[id^=new_napravlenie_][id$=_type] select').prop('selectedIndex',0); | |
| $('[id^=new_napravlenie_][id$=_type]').hide(300); | |
| $('[name^=new_napravlenie_][name$=_type]').prop('disabled', true); | |
| } | |
| }); | |
| |
| $("input:checkbox[name^=new_napravlenie_]").change(function() { | |
| var name = $(this).attr('name'); | |
| if ($(this).prop('checked')) { | |
| $("select[name='"+name+"_type']").prop('disabled', false); | |
| $('#'+name+'_type').show(300); | |
| } | |
| else { | |
| $('#'+name+'_type select').prop('selectedIndex',0); | |
| $("select[name='"+name+"_type']").prop('disabled', true); | |
| $('#'+name+'_type').hide(300); | |
| } | |
| }); | |
| */ | |
| |
| $("select[name='new_napravlenie_sel']").change(function() { | |
| if (this.value == "1") { | |
| $('[id^="new_napravlenie_fg_1"]').show(300); | |
| $('[id^="new_napravlenie_fg_2"]').hide(300); | |
| $('[id^="new_napravlenie_fg_3"]').hide(300); | |
| //$('[id^=new_napravlenie_other_2][id$=_comment]').hide(300); | |
| } | |
| else if (this.value == "2") { | |
| $('[id^="new_napravlenie_fg_2"]').show(300); | |
| $('[id^="new_napravlenie_fg_1"]').hide(300); | |
| $('[id^="new_napravlenie_fg_3"]').hide(300); | |
| } | |
| else if (this.value == "3") { | |
| $('[id^="new_napravlenie_fg_3"]').show(300); | |
| $('[id^="new_napravlenie_fg_1"]').hide(300); | |
| $('[id^="new_napravlenie_fg_2"]').hide(300); | |
| } | |
| /* | |
| else { | |
| $('[id^="new_napravlenie_fg_"]').hide(300); | |
| $("input:checkbox[name^=new_napravlenie_]").prop('checked', false); | |
| $('[id^=new_napravlenie_][id$=_type] select').prop('selectedIndex',0); | |
| $('[id^=new_napravlenie_][id$=_type]').hide(300); | |
| $('[name^=new_napravlenie_][name$=_type]').prop('disabled', true); | |
| $('[id^=new_napravlenie_other_2][id$=_comment]').show(300); | |
| } | |
| */ | |
| | |
| | |
| }); | |
| /* | |
| $("input:checkbox[name^=new_napravlenie_]").change(function() { | |
| var name = $(this).attr('name'); | |
| if ($(this).prop('checked')) { | |
| $("select[name='"+name+"_type']").prop('disabled', false); | |
| $('#'+name+'_type').show(300); | |
| } | |
| else { | |
| $('#'+name+'_type select').prop('selectedIndex',0); | |
| $("select[name='"+name+"_type']").prop('disabled', true); | |
| $('#'+name+'_type').hide(300); | |
| } | |
| }); | |
| */ | |
| $("input:checkbox[name^=new_napravlenie_]").change(function() { | |
| var name = $(this).attr('name'); | |
| if ($(this).prop('checked')) { | |
| $("select[name='"+name+"_type']").prop('disabled', false); | |
| $('#'+name+'_type').show(300); | |
| | |
| //для контраст-контраст | |
| $( "input[name='"+name+"_contrast']" ).prop('disabled', false); | |
| $( "input[name='"+name+"_contrast']" ).show(300); | |
| $( "div[id='"+name+"_contrast']" ).show(300); | |
| } | |
| else { | |
| $('#'+name+'_type select').prop('selectedIndex',0); | |
| $("select[name='"+name+"_type']").prop('disabled', true); | |
| $('#'+name+'_type').hide(300); | |
| | |
| //для контраст-контраст | |
| $( "input[name='"+name+"_contrast']" ).prop('disabled', true); | |
| $( "input[name='"+name+"_contrast']" ).hide(300); | |
| $( "div[id='"+name+"_contrast']" ).hide(300); | |
| } | |
| }); | |
| |
| $("#mkb10-tree").dynatree({ | |
| fx: { height: "toggle", duration: 200 }, | |
| autoCollapse: true, | |
| initAjax: { | |
| url: "mkb10-data.json" | |
| }, | |
| onActivate: function(node) { | |
| $("#new_patient_mkb10").val(node.data.key); | |
| }, | |
| onDeactivate: function(node) { | |
| $("#new_patient_mkb10").val(""); | |
| } | |
| }); | |
| |
| $('#mkb10-tree-edit').dynatree({ | |
| fx: { height: "toggle", duration: 200 }, | |
| autoCollapse: true, | |
| initAjax: { | |
| url: "mkb10-data.json" | |
| }, | |
| onActivate: function(node) { | |
| if(node.data.isFolder == false){ | |
| $("#mkb10_code").val(node.data.key); | |
| $("#mkb10").val(node.data.title); | |
| $('#mkb10-alert').hide(300); | |
| $('#mkb10').show(300); | |
| } | |
| } | |
| }); | |
| |
| |
| $('#mkb10').click(function(){ | |
| $('#mkb10').hide(300); | |
| $('#mkb10-alert').show(300); | |
| }); | |
| |
| |
| $('#stat_diagnoz').popover({ | |
| html: true, | |
| trigger: 'manual', | |
| placement: 'bottom', | |
| template: '<div class="popover popover-mkb10"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>', | |
| content: '<div id="mkb10-tree-popover" name="mkb10-tree-popover"></div>' | |
| }).click(function(e) { | |
| $(this).popover('toggle'); | |
| $("#mkb10-tree-popover").dynatree({ | |
| fx: { height: "toggle", duration: 200 }, | |
| autoCollapse: true, | |
| initAjax: { | |
| url: "mkb10-data.json" | |
| }, | |
| onActivate: function(node) { | |
| if(node.data.isFolder == false){ | |
| $("#stat_diagnoz_mkb10").val(node.data.key); | |
| $("#stat_diagnoz").val(node.data.title); | |
| $("#stat_diagnoz").popover('toggle'); | |
| } | |
| }, | |
| onDeactivate: function(node) { | |
| $("#stat_diagnoz_mkb10").val(""); | |
| $("#stat_diagnoz").val(""); | |
| } | |
| }); | |
| |
| }); | |
| |
| |
| $("button[name='print_napravlenie']").click(function(){ | |
| var id = $(this).closest("form").find("input[name='napravlenie_id']").val(); | |
| var url = 'index.php?action=print_napravlenie&id='+id; | |
| window.open(url); | |
| }); | |
| |
| |
| |
| $('#new_patient, #edit_patient').on('keydown', 'input', function (event) { | |
| if (event.which == 13) { | |
| event.preventDefault(); | |
| var $this = $(event.target); | |
| var index = parseFloat($this.attr('data-index')); | |
| $('[data-index="' + (index + 1).toString() + '"]').focus(); | |
| } | |
| }); | |
| |
| $(".oms_input").bind("input", function() { | |
| var $this = $(this); | |
| setTimeout(function() { | |
| if ( $this.val().length >= parseInt($this.attr("maxlength"),10) ) | |
| $this.next("input").focus(); | |
| },0); | |
| }); | |
| |
| }); | |
| |
| function doClearForm() { | |
| |
| $('.form-horizontal')[0].reset(); | |
| $('#stat_diagnoz_mkb10').val(''); | |
| $( "button[id='jqgrid_btn']" ).click(); | |
| | |
| } | |
| |
| |
| |
| </code> | |