mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-08 21:52:55 +08:00
Limit length of soft descriptor in front and backend
This commit is contained in:
parent
606c1e27c0
commit
d7829b11d3
3 changed files with 23 additions and 2 deletions
|
@ -0,0 +1,19 @@
|
|||
import ControlTextInput from './ControlTextInput';
|
||||
|
||||
const SoftDescriptorInput = ( { value, onChange, placeholder } ) => {
|
||||
const handleChange = ( newValue ) => {
|
||||
if ( newValue.length <= 22 ) {
|
||||
onChange( newValue );
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ControlTextInput
|
||||
value={ value }
|
||||
onChange={ handleChange }
|
||||
placeholder={ placeholder }
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default SoftDescriptorInput;
|
|
@ -9,6 +9,7 @@ import {
|
|||
import SettingsBlock from '../../../../../ReusableComponents/SettingsBlock';
|
||||
import Accordion from '../../../../../ReusableComponents/AccordionSection';
|
||||
import { SettingsHooks } from '../../../../../../data';
|
||||
import SoftDescriptorInput from '../../../../../ReusableComponents/Controls/SoftdescriptorInput';
|
||||
|
||||
const PaypalSettings = () => {
|
||||
const {
|
||||
|
@ -91,7 +92,7 @@ const PaypalSettings = () => {
|
|||
'woocommerce-paypal-payments'
|
||||
) }
|
||||
>
|
||||
<ControlTextInput
|
||||
<SoftDescriptorInput
|
||||
value={ softDescriptor }
|
||||
onChange={ setSoftDescriptor }
|
||||
placeholder={ __(
|
||||
|
|
|
@ -139,7 +139,8 @@ class SettingsModel extends AbstractDataModel {
|
|||
* @param string $descriptor The soft descriptor to set.
|
||||
*/
|
||||
public function set_soft_descriptor( string $descriptor ) : void {
|
||||
$this->data['soft_descriptor'] = $this->sanitizer->sanitize_text( $descriptor );
|
||||
$trimmed_descriptor = substr( $descriptor, 0, 22 );
|
||||
$this->data['soft_descriptor'] = $this->sanitizer->sanitize_text( $trimmed_descriptor );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue