feat: enable patient form interactions and revision-aware signing
This commit is contained in:
@@ -271,13 +271,15 @@ function buildOptionItem(
|
||||
displayValue: string = itemValue,
|
||||
): HTMLElement {
|
||||
const item = doc.createElement('span')
|
||||
item.className = [
|
||||
OPTION_CLASS,
|
||||
on ? OPTION_ON_CLASS : '',
|
||||
interactive ? OPTION_TICK_CLASS : '',
|
||||
]
|
||||
item.className = [OPTION_CLASS, on ? OPTION_ON_CLASS : '', interactive ? OPTION_TICK_CLASS : '']
|
||||
.filter(Boolean)
|
||||
.join(' ')
|
||||
if (interactive) {
|
||||
item.setAttribute('role', 'checkbox')
|
||||
item.setAttribute('tabindex', '0')
|
||||
item.setAttribute('aria-checked', String(on))
|
||||
item.setAttribute('aria-label', displayValue || '勾选此项')
|
||||
}
|
||||
item.setAttribute(OPTION_VALUE_ATTR, itemValue)
|
||||
item.setAttribute(OPTION_TEXT_ATTR, displayValue)
|
||||
item.textContent = optionDisplay(displayValue, on)
|
||||
@@ -288,6 +290,7 @@ function buildOptionItem(
|
||||
/** 切换一个选项的勾选态(改类名 + 重建 ☑ / ☐ 文案),返回切换后的状态 */
|
||||
function setOptionState(item: HTMLElement, on: boolean): boolean {
|
||||
item.classList.toggle(OPTION_ON_CLASS, on)
|
||||
if (item.hasAttribute('aria-checked')) item.setAttribute('aria-checked', String(on))
|
||||
item.textContent = optionDisplay(item.getAttribute(OPTION_TEXT_ATTR) ?? '', on)
|
||||
|
||||
return on
|
||||
@@ -409,7 +412,8 @@ function buildFieldWidget(
|
||||
if (interactive) {
|
||||
const input = doc.createElement('input')
|
||||
input.className = INPUT_CLASS
|
||||
input.type = 'text'
|
||||
input.type = field.kind === 'date' ? 'date' : 'text'
|
||||
input.maxLength = 4000
|
||||
input.value = text
|
||||
// value 属性同理:只设 property 的话序列化出来是空值
|
||||
input.setAttribute('value', text)
|
||||
@@ -509,7 +513,15 @@ function renderStructuredFields(
|
||||
return
|
||||
}
|
||||
|
||||
element.replaceWith(buildFieldWidget(doc, field, answers, interactive, signatureActionable))
|
||||
const readonly = element.getAttribute('data-readonly') === 'true'
|
||||
const widget = buildFieldWidget(
|
||||
doc,
|
||||
readonly ? { ...field, required: false } : field,
|
||||
answers,
|
||||
interactive && !readonly,
|
||||
signatureActionable && (!readonly || field.id === PRIMARY_SIGNATURE_FIELD_ID),
|
||||
)
|
||||
element.replaceWith(widget)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -555,7 +567,7 @@ function convertCheckboxTables(root: Element, interactive: boolean, selected: Se
|
||||
const cells = Array.from(row.querySelectorAll('td, th'))
|
||||
const checkCell = cells[checkIndex]
|
||||
|
||||
if (!checkCell) {
|
||||
if (!checkCell || checkCell.querySelector('[data-sign-field], [data-field]')) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -853,9 +865,8 @@ export function readAnswersFromRoot(root: HTMLElement): SigningAnswers {
|
||||
// 直接落库会在证据里留下一个 undefined 而不是 false
|
||||
if (kind === 'checkbox') {
|
||||
answers[id] =
|
||||
host
|
||||
.querySelector<HTMLElement>(`.${OPTION_CLASS}`)
|
||||
?.classList.contains(OPTION_ON_CLASS) ?? false
|
||||
host.querySelector<HTMLElement>(`.${OPTION_CLASS}`)?.classList.contains(OPTION_ON_CLASS) ??
|
||||
false
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user