mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Add validation for function parameters names
This commit is contained in:

committed by
Florian Rival

parent
3f92fc2ee5
commit
a61784bb6c
@@ -15,7 +15,9 @@ import {
|
||||
type EnumeratedObjectMetadata,
|
||||
} from '../ObjectsList/EnumerateObjects';
|
||||
import HelpButton from '../UI/HelpButton';
|
||||
import SemiControlledTextField from '../UI/SemiControlledTextField';
|
||||
import MiniToolbar, { MiniToolbarText } from '../UI/MiniToolbar';
|
||||
import { showWarningBox } from '../UI/Messages/MessageBox';
|
||||
|
||||
const gd = global.gd;
|
||||
|
||||
@@ -43,6 +45,17 @@ const styles = {
|
||||
},
|
||||
};
|
||||
|
||||
const validateParameterName = (newName: string) => {
|
||||
if (!gd.Project.validateObjectName(newName)) {
|
||||
showWarningBox(
|
||||
'This name contains forbidden characters: please only use alphanumeric characters (0-9, a-z) and underscores in your parameter name.'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export default class EventsFunctionConfigurationEditor extends React.Component<
|
||||
Props,
|
||||
State
|
||||
@@ -158,16 +171,17 @@ export default class EventsFunctionConfigurationEditor extends React.Component<
|
||||
<MiniToolbar>
|
||||
<MiniToolbarText>Parameter #{i + 1}:</MiniToolbarText>
|
||||
<Column expand noMargin>
|
||||
<TextField
|
||||
<SemiControlledTextField
|
||||
hintText="Enter the parameter name"
|
||||
value={parameter.getName()}
|
||||
onChange={(e, text) => {
|
||||
onChange={text => {
|
||||
if (!validateParameterName(text)) return;
|
||||
|
||||
parameter.setName(text);
|
||||
this.forceUpdate();
|
||||
}}
|
||||
onBlur={() => {
|
||||
this.props.onParametersUpdated();
|
||||
}}
|
||||
commitOnBlur
|
||||
/>
|
||||
</Column>
|
||||
<IconMenu
|
||||
@@ -202,8 +216,14 @@ export default class EventsFunctionConfigurationEditor extends React.Component<
|
||||
value="string"
|
||||
primaryText="String (text)"
|
||||
/>
|
||||
<MenuItem value="key" primaryText="Keyboard Key (text)" />
|
||||
<MenuItem value="mouse" primaryText="Mouse button (text)" />
|
||||
<MenuItem
|
||||
value="key"
|
||||
primaryText="Keyboard Key (text)"
|
||||
/>
|
||||
<MenuItem
|
||||
value="mouse"
|
||||
primaryText="Mouse button (text)"
|
||||
/>
|
||||
</SelectField>
|
||||
</Column>
|
||||
{parameter.getType() === 'objectList' && (
|
||||
|
Reference in New Issue
Block a user