cerebrate/app/templates/element/genericElements/Form/Fields/uuidField.php

43 lines
1.3 KiB
PHP
Raw Normal View History

<?php
$random = Cake\Utility\Security::randomString(8);
$params['div'] = false;
$this->Form->setTemplates([
'inputContainer' => '{{content}}',
'inputContainerError' => '{{content}}',
'formGroup' => '{{input}}',
]);
$label = $fieldData['label'];
$temp = sprintf(
'<div class="form-group row ">
<div class="col-sm-2 col-form-label">%s</div>
<div class="col-sm-10">
<div class="input-group">
%s<span class="input-group-append">%s</span>
</div>
</div>
</div>',
h($label),
$form->control($fieldData['field'], $params),
sprintf(
'<span id="uuid-gen-%s" class="btn btn-secondary">%s</span>',
$random,
__('Generate')
)
);
echo $temp;
?>
<script type="text/javascript">
$(document).ready(function() {
$('#uuid-gen-<?= h($random) ?>').on('click', function() {
$.ajax({
success:function (data, textStatus) {
$('#uuid').val(data["uuid"]);
},
type: "get",
cache: false,
url: "/organisations/generateUUID",
});
});
});
</script>