I am facing with the problem, that when user inserts into text field "\" char and this field has inline edit functionality it breaks the whole page, table structure breaks also if this field is inside some pageBlockTable
Part of vf page:
<apex:pageBlockTable id="tabTable" value="{!tabs}" var="tab">
<apex:column headerValue="Name" >
<apex:outputField value="{!tab.Name}" rendered="{!tab.Id != null}" >
<apex:inlineEditSupport event="ondblClick" />
</apex:outputField>
<apex:inputField value="{!tab.Name}" rendered="{!tab.Id == null}" />
</apex:column>
I added some methods into controller, which remove this char, but as ui is broken it doesnt refresh the page. So user should refresh it manually or click "Save" again.
Clean method:
public static SObject cleanRecordStringFields(SObject record) {
if (record != null) {
List<DescribeFieldResult> stringFields = getStringFieldsOfRecord(record);
//sanitize string fields
for (DescribeFieldResult field : stringFields) {
String fieldValue = (String) record.get(field.getName());
if ( String.isNotBlank( fieldValue ) ) {
String sanitizedString = sanitizeStringValue(fieldValue);
//check field's max length
sanitizedString = sanitizedString.length() > field.getLength()
? sanitizedString.substring(0, field.getLength()) : sanitizedString;
record.put( field.getName(), sanitizedString );
}
}
}
return record;
}
Any beautiful solution to this situation? I thought to add some field validation in controller, but as we have a lot of objects with text fields and i cannot use addError() with dynamic apex, its a pain to add to each field validation and maintain this in future :(