Wrap a field within a bootstrap form-group. Additionally sets has-error

    This decorator sets has-error if the field has any errors.
500044
def form_group_wrapped(f):
    
    @wraps(f)
    def wrapped(self, field, *args, **kwargs):
        classes = ['form-group']
        if field.errors:
            classes.append('has-error')

        html = """<div class="{classes}">{rendered_field}</div>""".format(
            classes=' '.join(classes),
            rendered_field=f(self, field, *args, **kwargs)
        )
        return HTMLString(html)

    return wrapped
347445
def validate_wrap(self, value, *types):
        '''  '''
        for type in types:
            if isinstance(value, type):
                break
        else:
            self._fail_validation_type(value, *types)

        if self.min is not None and value < self.min:
            self._fail_validation(value, 'Value too small')
        if self.max is not None and value > self.max:
            self._fail_validation(value, 'Value too large')
1346265
protected function wrapField(&$fieldStub, Field $field, $standardLabel = true, $required = '')
    {
        $stub = $this->getStubContent('form-input-wrapper.blade', $this->template);

        $this->replaceFieldName($stub, $field->name)
            ->replaceCssClass($stub, $field->cssClass)
            ->replaceFieldLabel($stub, $this->getLabelFromField($standardLabel ? $field : null))
            ->replaceFieldValidationHelper($stub, $this->getNewHelper($field))
            ->replaceFieldInput($stub, $fieldStub)
            ->replaceRequiredClass($stub, $required);

        $fieldStub = $stub;

        return $this;
    }
756029
def _render_errors(field):
    
    template = '{0}/layout/field_errors.html'.format(appsettings.CRISPY_TEMPLATE_PACK)
    return render_to_string(template, {
        'field': field,
        'form_show_errors': True,
    })
608121
def formfield(self, **kwargs):
        
        defaults = {
            'label': capfirst(self.verbose_name),
            'help_text': self.help_text,
            'required': not self.blank,
        }
        defaults.update(kwargs)
        return PlaceholderFormField(slot=self.slot, plugins=self._plugins, **defaults)
696483
def bootstrap_form_with(**options, &block)
      bootstrap_options = options[:bootstrap] || {}

      css_classes = options.delete(:class)

      if bootstrap_options[:layout].to_s == "inline"
        css_classes = [css_classes, "form-inline"].compact.join(" ")
      end

      form_options = options.reverse_merge(builder: ComfyBootstrapForm::FormBuilder)
      form_options.merge!(class: css_classes) unless css_classes.blank?

      supress_form_field_errors do
        form_with(**form_options, &block)
      end
    end
801957
def as_uni_errors(form):
    
    if isinstance(form, BaseFormSet):
        template = get_template('uni_form/errors_formset.html')
        c = Context({'formset': form})
    else:
        template = get_template('uni_form/errors.html')
        c = Context({'form':form})
    return template.render(c)
624342
function formFieldPartial (field) {
    if (field.legend) {
        return 'form/field-legend'
    }
    else if (field.nested) {
        if (field.array) {
            return 'form/field-nested-array'
        }
    }
    else {
        return `form/field-${field.inputType}`
    }
}
24299
def render_form_errors(form, error_types="non_field_errors", **kwargs):
    
    renderer_cls = get_form_renderer(**kwargs)
    return renderer_cls(form, **kwargs).render_errors(error_types)
551979
def validate_wrap(self, value):
        ''' 
        '''
        if not isinstance(value, self.type):
            self._fail_validation_type(value, self.type)
507606
def _wrap_field(field):
    """"""
    class WrappedField(field):
        def output(self, key, obj):
            value = _fields.get_value(key if self.attribute is None else self.attribute, obj)

            # For all fields, when its value was null (None), return null directly,
            #  instead of return its default value (eg. int type's default value was 0)
            # Because sometimes the client **needs** to know, was a field of the model empty, to decide its behavior.
            return None if value is None else self.format(value)
    return WrappedField
1280047
def validate_wrap(self, value):
        '''  '''
        if not isinstance(value, basestring):
            self._fail_validation_type(value, basestring)
        if self.regex.match(value) is None:
            self._fail_validation(value, 'Value does not match regular expression')
536007
def meta_wrapped(f):
    
    @wraps(f)
    def wrapped(self, field, *args, **kwargs):
        html = "{label}{errors}{original}<small>{description}</small>".format(
            label=field.label(class_='control-label'),
            original=f(self, field, *args, **kwargs),
            errors=render_field_errors(field) or '',
            description=render_field_description(field)
        )
        return HTMLString(html)
    return wrapped
178513
def wrap_form_params(func):
    

    @functools.wraps(func)
    def wrapper(request, *args, **kwargs):
        ctype, pdict = parse_header(request.headers.get('Content-Type', ''))
        if ctype == "application/x-www-form-urlencoded":
            params = {}
            for key, value in parse_qs(request.body.decode("utf-8")).items():
                if len(value) == 1:
                    params[key] = value[0]
                else:
                    params[key] = value

            request.params = merge_dicts(getattr(request, "params", None), params)
            request.form_params = params
        return func(request, *args, **kwargs)
    return wrapper
55306
def add_bootstrap_class(field):
    
    if not isinstance(field.field.widget, (
        django.forms.widgets.CheckboxInput,
        django.forms.widgets.CheckboxSelectMultiple,
        django.forms.widgets.RadioSelect,
        django.forms.widgets.FileInput,
        str
    )):
        field_classes = set(field.field.widget.attrs.get('class', '').split())
        field_classes.add('form-control')
        field.field.widget.attrs['class'] = ' '.join(field_classes)
    return field
527442
protected function wrapField($item, $field)
    {
        $formGroup = File::get($this->viewDirectoryPath . 'form-fields/wrap-field.blade.stub');

        $labelText = "'" . ucwords(strtolower(str_replace('_', ' ', $item['name']))) . "'";

        if ($this->option('localize') == 'yes') {
            $labelText = 'trans(\'' . $this->crudName . '.' . $item['name'] . '\')';
        }

        return sprintf($formGroup, $item['name'], $labelText, $field);
    }
1195199
function setUnits (form, fieldGroup) {
    var hasUnit = false
    var noUnit = false
    // check all fields in group to see if they have unit field
    _.each(fieldGroup, field => {
        if (field.unit) {
            hasUnit = true
        }
        else {
            noUnit = true
        }
    })
    // if some fields have unit property and other dont throw error
    assert.ok(!(hasUnit && noUnit), 'some fields do not have unit')
    // if unit already defined do nothing
    if (hasUnit) {
        return
    }
    // 
    var units = fieldGroup.length
    // add unit property to each
    _.each(fieldGroup, field => {
        field.unit = '1-'+units
    })
}