当我用正常请求(非ajax)打开页面时,一切正常.但是当我用ajax加载该表单时,该表单中的客户端验证不起作用.
表单生成器是经典的gii生成的东西:
$form = $this->beginWidget('CActiveForm', array(
'id'=>'cat-form',
'enableAjaxValidation'=>true,
'action' => ...,
'clientOptions'=>array('validateOnSubmit'=>true),
)
);
// - form inputs go here -
$this->endWidget();
Run Code Online (Sandbox Code Playgroud)
Ajax加载是这样完成的:
$.get(page, function(formHtml) {
$('#content').html(formHtml);
});
Run Code Online (Sandbox Code Playgroud)
我不得不调用renderPartial processOutput = true,以便输出javascript.小部件生成的JavaScript看起来像这样:
$('#cat-form').yiiactiveform({'validateOnSubmit':true,'attributes':[...]});
Run Code Online (Sandbox Code Playgroud)
我已经将问题追溯到这样一个事实:当$('#cat-form')选择完成时,返回的jQuery对象是空的,即还没有表单.
如何在Yii中为ajax加载的内容正确添加客户端验证?
我很蠢,因为这个而浪费了4个小时:
var slider = $('.slider');
var slide = $('<div class="slide">').html(resp); // facepalm
// few lines later..
slider.append(slide);
Run Code Online (Sandbox Code Playgroud)
因此,当表单仅在临时元素中时,脚本已执行,该元素尚未附加到页面.因此,$('#form')没有找到任何东西.
我正在将游戏地图绘制到画布上。地面由瓷砖制成 - 简单的 64x64 png 图像。
当我在 Chrome 中绘制它时,它看起来不错(左),但是当我在 Firefox/Opera/IE 中绘制它时(右),我得到了可见的边缘:

当我使用四舍五入的数字时,问题就消失了:
ctx.drawImage(img, parseInt(x), parseInt(y), w, h);
Run Code Online (Sandbox Code Playgroud)
但这在我使用缩放时无济于事:
ctx.scale(scale); // anything from 0.1 to 2.0
Run Code Online (Sandbox Code Playgroud)
我也试过这些,但没有改变:
ctx.drawImage(img, 5, 5, 50, 50, x, y, w, h); // so not an issue of clampingctx.imageSmoothingEnabled = false;image-rendering: -moz-crisp-edges; (css)有没有办法让它在ff/op/ie中工作?
将 1 像素添加到宽度/高度并按比例(宽度 + 1/比例)进行补偿似乎有帮助:
ctx.drawImage(props.img, 0, 0, width + 1/scale, height + 1/scale);
Run Code Online (Sandbox Code Playgroud)
它制造了一些文物,但我认为这是可以接受的。在这张图片上,你可以看到没有边缘的绿色瓷砖,以及没有补偿的蓝色窗口,仍然有可见的边缘:

使用Free Transform工具将图层旋转90度后......
如何使用jsx脚本找到此值?
当我在画布中绘制文本时,我会得到丑陋的尖峰,如下所示:

在这里试试:http://jsfiddle.net/48m4B/
例如在photoshop中,我得到了这个:

代码只是一个经典的strokeText:
ctx.font = '20px Arial';
ctx.lineWidth = 15;
ctx.strokeStyle = '#fff';
ctx.strokeText('How to prevent ugly spikes?');
Run Code Online (Sandbox Code Playgroud)
如果无法解决此问题,是否有解决方法?
在经典的gii生成的PHP代码中:
$form=$this->beginWidget('CActiveForm', array(
'id'=>'stuff-form',
'enableAjaxValidation'=>true, ...
Run Code Online (Sandbox Code Playgroud)
如果我设置'enableAjaxValidation'=> true,则会显示此javascript错误(并且验证不起作用):
Uncaught TypeError: Object [object Object] has no method 'yiiactiveform'
Run Code Online (Sandbox Code Playgroud) javascript ×3
php ×2
yii ×2
active-form ×1
ajax ×1
canvas ×1
html ×1
html5-canvas ×1
jquery ×1
jsx ×1
photoshop ×1
stroke ×1