Skip to content

Commit

Permalink
Support per-service config item allowAnyDate (#63)
Browse files Browse the repository at this point in the history
Disables date validation in forms.

Update docs, add tests.

Fixes PR-2059.
  • Loading branch information
MikeTaylor authored Dec 10, 2024
1 parent 6c7286f commit e0e9e69
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* "Please supply a ..." messages come and go depending on submitted request type. Fixes PR-1717.
* Do not assume that mod-rs's successful-POST response has a `serviceType` field. That assumption could cause an NPE under some circumstances. No Jira issue.
* Make robust against old version of mod-rs (e.g. 2.15.5) that do not return lists of copyright types. Fixes PR-1841.
* Support per-service config item `allowAnyDate` to disable date validation in forms. Update docs, add tests. Fixes PR-2059.

## [1.6.0](https://github.com/openlibraryenvironment/listener-openurl/tree/v1.6.0) (2024-03-04)

Expand Down
3 changes: 2 additions & 1 deletion config/openurl.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"okapiUrl": "https://north-okapi.folio-dev.indexdata.com",
"tenant": "reshare_north",
"username": "north_admin",
"password": "north5231"
"password": "north5231",
"allowAnyDate": true
}
}
}
2 changes: 1 addition & 1 deletion config/templates/form1.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ <h2>Publication Details</h2>
<div id="div-publicationDate" class="key-value-pair">
<label class="key" for="input-publicationDate">Year of publication</label>
<div class="value">
<input class="should-validate" id="input-publicationDate" name="rft.date" value="{{'rft.date'}}" pattern="[0-9]*" aria-required="true">
<input class="should-validate" id="input-publicationDate" name="rft.date" value="{{'rft.date'}}" {{{pubDateValidation}}}aria-required="true">
<div id="error-publicationDate" class="error"></div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions doc/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ These all contain the names of [template](#templates) to be used when generating

To specify several different back-ends, provide a directory under the `services` key ([example](https://github.com/openlibraryenvironment/listener-openurl/blob/a68a71b8d2feab37e3cc24ad5444396e53668c6b/config/caliban.json#L10-L36)). Within this sub-object, each key is the identifier of a service, and the corresponding value is an object with most configuration listed above. These are used when the OpenURL resolver is accessed via a baseURL whose last path component is equal to the identifier. When the resolver is accessed using a baseURL that does not match any of the configured service identifiers, it falls back to using the default service configuration (`okapiURL` etc.) specified at the top level. `loggingCategories`, `listenPort` and `docRoot` are only valid at the top-level.

If the `allowAnyDate` configuration item is set for a service, then forms that require a publication date to be entered do not insist that it consist of four digits, allowing "fuzzy" dates such as "1950s", "c1935" or "17th Century".


### Templates

Expand Down
1 change: 1 addition & 0 deletions src/OpenURLServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ function makeFormData(ctx, query, service, valuesNotShownInForm, firstTry, npl)
name: x.charAt(0).toUpperCase() + x.slice(1),
checked: x === query.svc_id || (!query.svc_id && i === 0) ? 'checked' : '',
})),
pubDateValidation: ctx.state?.svcCfg?.allowAnyDate ? '' : 'pattern="[0-9]*" ',
});

const format = data.formats.filter(x => x.selected);
Expand Down
18 changes: 16 additions & 2 deletions test/06-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,28 @@ const tests = [
},
{
name: 'form1',
values: { json: {} },
values: { json: {}, pubDateValidation: 'pattern="[0-9]*" ' },
equalToFile: 'form1.html'
},
{
name: 'form2',
values: { json: {} },
equalToFile: 'form2.html'
}
},
{
name: 'form1',
values: { pubDateValidation: 'pattern="[0-9]*" ' },
checks: [
/id="input-publication-date".*pattern="\[0-9\]\*"/,
]
},
{
name: 'form1',
values: {},
checks: [
/value="" data-error="Please enter year/,
]
},
];

describe('06. substitute into templates', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/data/templates/form1.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h1>Request item</h1>
<label class="key-value-pair is-required" for="input-publication-date">
<div class="key">Year of publication</div>
<div class="value">
<input class="should-validate" id="input-publication-date" type="number" name="rft.date" value="{{'rft.date'}}" pattern="[0-9]*" data-error="Please enter year of publication" aria-describedby="input-publication-date-error" aria-required="true">
<input class="should-validate" id="input-publication-date" type="number" name="rft.date" value="{{'rft.date'}}" {{{pubDateValidation}}}data-error="Please enter year of publication" aria-describedby="input-publication-date-error" aria-required="true">
</div>
<div class="error" aria-live="on">
<div class="error-text-positioner">
Expand Down

0 comments on commit e0e9e69

Please sign in to comment.