Skip to content

Commit

Permalink
Merge pull request #329 from Kiho/option-key-value
Browse files Browse the repository at this point in the history
Use "key" or "value" of checked option item in json data
  • Loading branch information
Kiho authored Oct 25, 2024
2 parents 266847b + 8b10264 commit 82c75b8
Show file tree
Hide file tree
Showing 5 changed files with 6,213 additions and 7,534 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ skip_validations | boolean | Optional | Suppress form validations on submit, if
display_short | boolean | Optional | Display an optional "shorter page/form" which is common for legal documents or situations where the user will just have to sign or fill out a shorter form with only the critical elements.
read_only | boolean | Optional | Shows a read only version which has fields disabled and removes "required" labels.
variables | object | Optional | Key/value object that can be used for Signature variable replacement.
option_key_value | string | Optional | Use "key" or "value" of checked option item in json data, default is "key".

### Read only Signatures

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-form-builder2",
"version": "0.18.2",
"version": "0.18.3",
"description": "A complete form builder for react.",
"main": "lib/index.js",
"types": "types/index.d.ts",
Expand Down
7 changes: 6 additions & 1 deletion src/form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ class ReactForm extends React.Component {
return $item;
}

_getOptionKeyValue = (option) => {
return this.props.option_key_value === 'value' ?
option.value : option.key;
}

_isIncorrect(item) {
let incorrect = false;
if (item.canHaveAnswer) {
Expand Down Expand Up @@ -162,7 +167,7 @@ class ReactForm extends React.Component {
item.options.forEach(option => {
const $option = ReactDOM.findDOMNode(ref.options[`child_ref_${option.key}`]);
if ($option.checked) {
checked_options.push(option.key);
checked_options.push(this._getOptionKeyValue(option));
}
});
itemData.value = checked_options;
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export interface FormGeneratorProps {
authenticity_token?: string;
hide_actions?: boolean;
skip_validations?: boolean;
option_key_value?: 'key' | 'value';
display_short?: boolean;
read_only?: boolean;
// eslint-disable-next-line no-undef
Expand Down
Loading

0 comments on commit 82c75b8

Please sign in to comment.