{% macro standard_input(field, style=None) %}
    <input type="{{ field.type }}"
		   class="{{ field.input_classes }}"
	       name="{{ field.name }}"
	       id="{{ field.id }}" value="{{ field.value|sn }}" placeholder="{{ field.placeholder|sn }}"
	       {% if field.readonly %}readonly{% endif %}
	       {% if field.min_value is defined and field.min_value != None %}min="{{ field.min_value }}"{% endif %}
	       {% if field.max_value is defined and field.max_value != None %}max="{{ field.max_value }}"{% endif %}
	       {% if field.step is defined and field.step != None %}step="{{ field.step }}"{% endif %}
		   {% if style is not none %}style="{{ style }}"{% endif %}>
{% endmacro %}


{% macro input_group(field) %}
	{% if field.pre_units or field.units %}
		<div class="input-group">
	{% endif %}
		{% if field.pre_units %}
			{% if field.style == styles.BOOTSTRAP_3 %}
				<span class="input-group-addon">{{ field.pre_units }}</span>
			{% elif field.style == styles.BOOTSTRAP_4 %}
				<div class="input-group-prepend">
					<span class="input-group-text">{{ field.pre_units }}</span>
				</div>
			{% endif %}
		{% endif %}

		{{ caller() }}

		{% if field.units %}
			{% if field.style == styles.BOOTSTRAP_3 %}
				<span class="input-group-addon">{{ field.units }}</span>
			{% elif field.style == styles.BOOTSTRAP_4 %}
				<div class="input-group-append">
					<span class="input-group-text">{{ field.units }}</span>
				</div>
			{% endif %}
		{% endif %}
	{% if field.pre_units or field.units %}
		</div>
		{# Hack for validation message to appear properly #}
		{% if field.style == styles.BOOTSTRAP_4 and field.error %}
			<span class="{{ field.input_classes }}" style="display: none;"></span>
		{% endif %}
	{% endif %}
{% endmacro %}


{% macro standard_label(field) %}
	{% if field.label_width > 0 %}
		<label for="{{ field.id }}" class="{{ field.label_column_class }}">
			{{ field.label_html }}
			{% if field.optional %}
				<span class="info">(optional)</span>
			{% endif %}
		</label>
	{% endif %}
{% endmacro %}


{% macro standard_error(field) %}
	{{ bs3_error(field) }}
{% endmacro %}


{% macro bs3_error(field) %}
	{% if field.error and field.style == styles.BOOTSTRAP_3 %}
		<div class="{{ field.error_column_class }}">
			<p class="help-block">
				{# This invisible label pushed the validation message to be in line with the input #}
				{% if field.form.form_type == formtype.INLINE %}
					<span style="visibility: hidden">
						{{ standard_label(field) }}
					</span>
				{% endif %}
				{{ field.error }}
			</p>
		</div>
	{% endif %}
{% endmacro %}


{% macro bs4_error(field) %}
	{% if field.error and field.style == styles.BOOTSTRAP_4 %}
		<div class="invalid-feedback">
			{{ field.error }}
		</div>
	{% endif %}
{% endmacro %}


{% macro bs3_help_text(field) %}
	{% if field.help_text and field.style == styles.BOOTSTRAP_3 %}
 		<div class="{{ field.help_text_column_class }}">
 			<p class="help-block">
 				{{ field.help_text }}
 			</p>
 		</div>
 	{% endif %}
 {% endmacro %}


{% macro bs4_help_text(field) %}
	{% if field.help_text and field.style == styles.BOOTSTRAP_4 %}
		<small class="form-text text-muted">
			{{ field.help_text }}
		</small>
	{% endif %}
{% endmacro %}


{% macro standard_help_text(field) %}
	{{ bs3_help_text(field) }}
	{{ bs4_help_text(field) }}
{% endmacro %}

