mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-26 09:43:29 +08:00
Switch input type to text for Numbers in repositories [SCI-4258]
This commit is contained in:
parent
16724f622c
commit
fa0bff93ff
3 changed files with 17 additions and 7 deletions
|
@ -133,17 +133,23 @@ $.fn.dataTable.render.editRepositoryChecklistValue = function(formId, columnId,
|
|||
ChecklistColumnHelper.initialChecklistEditMode(formId, columnId, $cell, currentValue);
|
||||
};
|
||||
|
||||
$.fn.dataTable.render.editRepositoryNumberValue = function(formId, columnId, cell) {
|
||||
$.fn.dataTable.render.editRepositoryNumberValue = function(formId, columnId, cell, $header) {
|
||||
let $cell = $(cell.node());
|
||||
let decimals = $header.data('metadata-decimals');
|
||||
let number = $cell.find('.number-value').data('value');
|
||||
|
||||
if (!number) number = '';
|
||||
|
||||
$cell.html(`
|
||||
<div class="sci-input-container text-field">
|
||||
<input class="sci-input-field"
|
||||
form="${formId}"
|
||||
type="number"
|
||||
type="text"
|
||||
oninput="this.value = this.value.replace(/[^0-9.]/g, '');
|
||||
this.value = this.value.match(/^\\d*(\\.\\d{0,${decimals}})?/)[0];"
|
||||
name="repository_cells[${columnId}]"
|
||||
placeholder="${I18n.t('repositories.table.number.enter_number')}"
|
||||
value="${$cell.find('.number-value').data('value')}"
|
||||
value="${number}"
|
||||
data-type="RepositoryNumberValue">
|
||||
</div>`);
|
||||
};
|
||||
|
|
|
@ -64,12 +64,16 @@ $.fn.dataTable.render.newRepositoryChecklistValue = function(formId, columnId, $
|
|||
ChecklistColumnHelper.initialChecklistEditMode(formId, columnId, $cell);
|
||||
};
|
||||
|
||||
$.fn.dataTable.render.newRepositoryNumberValue = function(formId, columnId, $cell) {
|
||||
$.fn.dataTable.render.newRepositoryNumberValue = function(formId, columnId, $cell, $header) {
|
||||
let decimals = $header.data('metadata-decimals');
|
||||
|
||||
$cell.html(`
|
||||
<div class="sci-input-container text-field">
|
||||
<input class="sci-input-field"
|
||||
form="${formId}"
|
||||
type="number"
|
||||
type="text"
|
||||
oninput="this.value = this.value.replace(/[^0-9.]/g, '');
|
||||
this.value = this.value.match(/^\\d*(\\.\\d{0,${decimals}})?/)[0];"
|
||||
name="repository_cells[${columnId}]"
|
||||
value=""
|
||||
placeholder="${I18n.t('repositories.table.number.enter_number')}"
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
module RepositoryDatatable
|
||||
class RepositoryNumberValueSerializer < RepositoryBaseValueSerializer
|
||||
def value
|
||||
decimal_number = scope[:column].metadata.fetch('decimals') { Constants::REPOSITORY_NUMBER_TYPE_DEFAULT_DECIMALS }
|
||||
BigDecimal(object.data).round(decimal_number.to_i)
|
||||
decimals = scope[:column].metadata.fetch('decimals', Constants::REPOSITORY_NUMBER_TYPE_DEFAULT_DECIMALS).to_i
|
||||
object.data.round(decimals).to_s('F').remove(/.0+$/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue