-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapitt.js
More file actions
56 lines (46 loc) · 1.94 KB
/
apitt.js
File metadata and controls
56 lines (46 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// CDN Source
//----------------------Inputy---------------------//
function styleInputs(inputID) {
var parentDiv = $('#' + inputID).closest('.cell');
parentDiv.find('.info').hide();
parentDiv.addClass('govuk-inset-text govuk-form-group');
parentDiv.find('.fieldLabel').addClass('govuk-label');
var inputElement = $('#' + inputID);
inputElement.addClass('govuk-input');
var altText = inputElement.attr('alt');
if (inputElement.prop('required')) {
parentDiv.find('.fieldLabel').append(' <span class="govuk-required">*</span>');
}
if (inputElement.prop('readonly')) {
inputElement.addClass('govuk-input--readonly');
}
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName === "class") {
var parentInsetDiv = $('#' + inputID).closest('.govuk-inset-text');
if ($('#' + inputID).hasClass('error')) {
// Zmeňte farbu okraja na červenú, ak je chyba
parentInsetDiv.css('border-color', 'red');
} else {
// Zmeňte farbu okraja späť na pôvodnú, ak nie je chyba
parentInsetDiv.css('border-color', ''); // alebo ktorákoľvek predvolená farba
}
}
});
});
observer.observe(inputElement[0], {
attributes: true
});
var hintText = $('<span/>').attr('id', inputID + '-hint').text(altText).addClass('govuk-hint');
inputElement.attr('aria-describedby', inputID + '-hint');
inputElement.before(hintText);
}
function styleAllInputs() {
// Iterácia cez všetky inputy, ktorých id začína na 'input_'
$("input[id^='input_']").each(function() {
// Získanie hodnoty id atribútu
var inputID = $(this).attr('id');
// Zavolanie funkcie styleInputs pre každý input
styleInputs(inputID);
});
}