HTML attr encoding for UploadField config

Also fixed UploadField operation with canUpload=false,
which broke the JS because no config could be found,
since the <input> field wasn't present. We can't put the data-config
attribute on the field holder, since fields can be rendered
without their field holder through FormField->SmalLFieldHolder().

Fixes https://github.com/silverstripe/silverstripe-cms/issues/874
This commit is contained in:
Ingo Schommer 2013-10-17 10:55:11 +02:00
parent 472bb4d2e2
commit e1b7df38ef
3 changed files with 5 additions and 5 deletions

View File

@ -1000,7 +1000,7 @@ class UploadField extends FileField {
$mergedConfig = array_merge($config, $this->ufConfig);
return $this->customise(array(
'configString' => str_replace('"', "'", Convert::raw2json($mergedConfig)),
'configString' => str_replace('"', "&quot;", Convert::raw2json($mergedConfig)),
'config' => new ArrayData($mergedConfig),
'multiple' => $allowedMaxFileNumber !== 1
))->renderWith($this->getTemplates());

View File

@ -151,9 +151,9 @@
if(this.is('.readonly,.disabled')) return;
var fileInput = this.find('input[type=file]');
var fileInput = this.find('.ss-uploadfield-fromcomputer-fileinput');
var dropZone = this.find('.ss-uploadfield-dropzone');
var config = $.parseJSON(fileInput.data('config').replace(/'/g,'"'));
var config = fileInput.data('config');
/* Attach classes to dropzone when element can be dropped*/
$(document).unbind('dragover');
@ -181,8 +181,6 @@
e.preventDefault();
});
this.setConfig(config);
this.fileupload($.extend(true,
{

View File

@ -52,6 +52,8 @@
<% _t('UploadField.FROMCOMPUTER', 'From your computer') %>
<input id="$id" name="{$Name}[Uploads][]" class="$extraClass ss-uploadfield-fromcomputer-fileinput" data-config="$configString" type="file"<% if $multiple %> multiple="multiple"<% end_if %> />
</label>
<% else %>
<input id="$id" name="{$Name}[Uploads][]" class="$extraClass ss-uploadfield-fromcomputer-fileinput" data-config="$configString" type="hidden" />
<% end_if %>
<% if $canAttachExisting %>