Overview
Comment:Fix issues with form values changed after POST and error
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable | 1.0.0-rc15
Files: files | file ages | folders
SHA1: 40c4254d8cd02bf68c84bf17d9097d1ec875c182
User & Date: bohwaz on 2020-12-16 17:36:43
Other Links: manifest | tags
Context
2020-12-16
18:44
Force checkbox to be an int check-in: 4f3a516b68 user: bohwaz tags: trunk, stable
17:36
Fix issues with form values changed after POST and error check-in: 40c4254d8c user: bohwaz tags: trunk, stable, 1.0.0-rc15
15:37
New release check-in: 9057a4c675 user: bohwaz tags: trunk, stable, 1.0.0-rc15
Changes

Modified src/include/lib/Garradin/Template.php from [f4f068b44b] to [9cbccdaf1f].

239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
		}
		elseif (isset($source) && is_object($source) && isset($source->$name)) {
			$current_value = $source->$name;
		}
		elseif (isset($source) && is_array($source) && isset($source[$name])) {
			$current_value = $source[$name];
		}
		elseif (isset($default)) {
			$current_value = $default;
		}

		if ($type == 'date' && is_object($current_value) && $current_value instanceof \DateTimeInterface) {
			$current_value = $current_value->format('d/m/Y');
		}
		elseif ($type == 'date' && is_string($current_value)) {







|







239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
		}
		elseif (isset($source) && is_object($source) && isset($source->$name)) {
			$current_value = $source->$name;
		}
		elseif (isset($source) && is_array($source) && isset($source[$name])) {
			$current_value = $source[$name];
		}
		elseif (isset($default) && !isset($_POST)) {
			$current_value = $default;
		}

		if ($type == 'date' && is_object($current_value) && $current_value instanceof \DateTimeInterface) {
			$current_value = $current_value->format('d/m/Y');
		}
		elseif ($type == 'date' && is_string($current_value)) {

Modified src/templates/services/save.tpl from [76ea220052] to [dcd4570d58].

108
109
110
111
112
113
114
115
116
117
118
119

120

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
		{/if}
	</p>

</form>

{literal}
<script type="text/javascript">
function selectService(elm) {
	$('[data-service]').forEach((e) => {
		e.style.display = ('s' + elm.value == e.getAttribute('data-service')) ? 'block' : 'none';
	});


	$('#f_expiry_date').value = elm.dataset.expiry;


	var first = document.querySelector('[data-service="s' + elm.value + '"] input[name=id_fee]');

	if (first) {
		first.checked = true;
		selectFee(first);
	}
}

function selectFee(elm) {
	var amount = parseInt(elm.getAttribute('data-user-amount'), 10);

	// Toggle accounting part of the form
	var accounting = elm.getAttribute('data-account') ? true : false;
	g.toggle('.accounting', accounting);
	$('#f_amount').required = accounting;

	// Fill the amount paid by the user
	if (amount) {
		$('#f_amount').value = g.formatMoney(amount);
	}
}

$('input[name=id_service]').forEach((e) => {
	e.onchange = () => { selectService(e); };
});

$('input[name=id_fee]').forEach((e) => {
	e.onchange = () => { selectFee(e); };
});

var selected = document.querySelector('input[name="id_service"]:checked, input[name="id_service"]');
selected.checked = true;

g.toggle('.accounting', false);
selectService(selected);

$('#f_create_payment_1').onchange = (e) => {
	g.toggle('.accounting dl', $('#f_create_payment_1').checked);
};
</script>
{/literal}

{include file="admin/_foot.tpl"}







|




>
|
>





|



|








|












|



|








108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
		{/if}
	</p>

</form>

{literal}
<script type="text/javascript">
function selectService(elm, first_load) {
	$('[data-service]').forEach((e) => {
		e.style.display = ('s' + elm.value == e.getAttribute('data-service')) ? 'block' : 'none';
	});

	if (!first_load) {
		$('#f_expiry_date').value = elm.dataset.expiry;
	}

	var first = document.querySelector('[data-service="s' + elm.value + '"] input[name=id_fee]');

	if (first) {
		first.checked = true;
		selectFee(first, first_load);
	}
}

function selectFee(elm, first_load) {
	var amount = parseInt(elm.getAttribute('data-user-amount'), 10);

	// Toggle accounting part of the form
	var accounting = elm.getAttribute('data-account') ? true : false;
	g.toggle('.accounting', accounting);
	$('#f_amount').required = accounting;

	// Fill the amount paid by the user
	if (amount && !first_load) {
		$('#f_amount').value = g.formatMoney(amount);
	}
}

$('input[name=id_service]').forEach((e) => {
	e.onchange = () => { selectService(e); };
});

$('input[name=id_fee]').forEach((e) => {
	e.onchange = () => { selectFee(e); };
});

var selected = document.querySelector('input[name="id_service"]:checked') || document.querySelector('input[name="id_service"]');
selected.checked = true;

g.toggle('.accounting', false);
selectService(selected, true);

$('#f_create_payment_1').onchange = (e) => {
	g.toggle('.accounting dl', $('#f_create_payment_1').checked);
};
</script>
{/literal}

{include file="admin/_foot.tpl"}