如何避免角度js中的十进制数?
<div class="col-md-6 col-sm-6">
<label class="col-md-5 col-sm-5 pad-top5 pad-lft-no">Mins <span class="error">*</span></label>
<input positive type="number" class="col-md-7 col-sm-7 cls_input_inherit numberinput" min="0" ng-maxlength="3" id="age_min" name="age_min" ng-model="attributes.age_min" step="1" required/>
<label for="age_min" ng-show="submittab2 && attributesForm2.age_min.$error.required" class="error">{{formValidation.required}}</label>
<label for="age_min" ng-show="submittab2 && !attributesForm2.age_min.$error.positive && attributesForm2.age_min.$error.maxlength" class="error"> {{formValidation.monthMaxChar}} </label>
<label for="age_min" ng-show="submittab2 && !attributesForm2.age_min.$error.positive && !attributesForm2.age_min.$error.maxlength && attributesForm2.age_min.$error.min" class="error">{{formValidation.minMax}}</label>
<label for="age_min" ng-show="submittab2 && !attributesForm2.age_min.$error.positive && !attributesForm2.age_min.$error.maxlength && attributesForm2.age_min.$error.number" class="error">{{formValidation.errorNumber}}</label>
<label for="age_min" ng-show="submittab2 && attributesForm2.age_min.$error.positive" class="error">{{formValidation.minpositive}}</label>
<label for="age_min" ng-show="submittab2 && attributesForm2.age_min.$error.required && attributesForm2.age_min.$invalid && attributesForm2.age_min.$touched" class="error">Invalid value</label>
</div>
当用户输入小数值时,它没有显示任何错误?我试过步骤=&#34; 1&#34;和ng-pattern一样,两个都不工作,我的代码是否有任何错误显示十进制值的错误消息?如何在用户输入十进制值时显示该错误消息?
答案 0 :(得分:2)
您可以使用ng-pattern。
class Image(BaseImage):
article = models.ForeignKey(Article, verbose_name=u'Новость', null=True)
in_preview = models.BooleanField(u'Отображать в превью', default=False)
weight = models.IntegerField(u'Порядок', default=0)
class Meta:
verbose_name = u'Изображение'
verbose_name_plural = u'Изображения'
ordering = ('weight',)
def get_upload_to(self, filename):
return os.path.join('articles', 'image', 'image_file', filename)
def list_thumbnail_tag(self):
source = self.image_file
if source:
thumbnail = get_thumbnailer(source).get_thumbnail({'size': (100, 100), 'crop': True})
return '<img src="{}">'.format(thumbnail.url)
list_thumbnail_tag.short_description = 'Превью'
list_thumbnail_tag.allow_tags = True
class BaseImage(models.Model):
image_file = models.ImageField(u'Файл', upload_to='uploads')
image_alt = models.CharField(u'Атрибут Alt', max_length=255, blank=True)
image_title = models.CharField(u'Название', max_length=255, blank=True)
def __str__(self):
return os.path.basename(self.image_file.path)
def get_upload_to(self, filename):
return os.path.join('images', filename)
class Meta:
abstract = True
verbose_name = u'Изображение'
verbose_name_plural = u'Изображения'
这是有效的Plunker