Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Bootstrap 5 in scaffolding templates without requiring fields template files #348

Open
codeconsole opened this issue Sep 6, 2024 · 1 comment

Comments

@codeconsole
Copy link
Contributor

codeconsole commented Sep 6, 2024

All generated Grails apps use Bootstrap. So why have a lot of unnecessary css rules and custom classes that cause nothing more that confusion for the developer? I have created new templates for Bootstrap 5 that have virtually no css rules, but require updates to the fields plugin so that fields templates are not also required.

There are also some general things that the fields plugin should change such as:

  1. Constantly render double quotes.
  2. User wrapper attributes when rendering the default wrapper.

src/main/templates/scaffolding/edit.gsp

<f:all bean="domain" />

generates several wrappers
grails-app/views/_fields/default/_wrapper.gsp

<div class='fieldcontain'>
    <label for='${(prefix?:'')}${property}'>
        <g:if test="${required}"><span class="required-indicator"> *</span></g:if>${label}
    </label>
    ${wdiget}
</div>

A bootstrap friendly version would allow modified <f:all />:

<f:all bean="domain" class="row" requiredClass="mb-3 required" labelClass="col-sm-2 col-form-label text-sm-end" divClass="col-sm-10" widget-class="form-control" widget-invalidClass="is-invalid" />
<f:all bean="domain" class="row" requiredClass="mb-3 required"
     labelClass="col-sm-2 col-form-label text-sm-end" divClass="col-sm-10" widget-class="form-control" />
<div class="row${required?' mb-3 required':''}${invalid?' invalid':''}">
    <label class="col-sm-2 col-form-label text-sm-end" for="${(prefix?:'')}${property}">${label}<g:if test="${required}"><span class="required-indicator"> *</span></g:if>
    </label>
    <div class="col-sm-10">${wdiget}</div>
</div>
@codeconsole
Copy link
Contributor Author

Looks like Grace Framework decided not to be backward compatible and also went straight to bootstrap class generation.

<fieldset class="form">
    <f:all bean="${propertyName}"/>
</fieldset>

results in:

<fieldset class="form">
    <div class="form-group row pb-3 has-error">
        <label for="prop1" class="col-3 col-form-label property-label text-end">Prop1 <span class="required-indicator">*</span></label>
        <div class="col-9">
            <input type="text" name="prop1" value="as" required="true" class="form-control col-8" id="widget.prop1">
            <span class="help-block">Property [prop1] of class [class website.Sample] with value [as] does not fall within the valid size range from [5] to [15]</span>
        </div>
    </div><div class="form-group row pb-3 ">
    <label for="prop2" class="col-3 col-form-label property-label text-end">Prop2 <span class="required-indicator">*</span></label>
    <div class="col-9">
        <input type="number" name="prop2" value="12" class="form-control col-2" max="100" step="1" id="prop2">
    </div>
</div><div class="form-group row pb-3 ">
    <label for="prop3" class="col-3 col-form-label property-label text-end">Prop3 <span class="required-indicator">*</span></label>
    <div class="col-9">
        <div class="hstack gap-3">
            <input type="hidden" name="prop3" value="date.struct">
            <label style="display:none;" for="prop3_month" id="label_prop3_month">Month</label>
            <select name="prop3_month" id="prop3_month" aria-labelledby="prop3 prop3_month" class="form-select w-20"><option value="" selected="selected">-Choose-</option>
            </select>
            <label style="display:none;" for="prop3_day" id="label_prop3_day">Day</label>
            <select name="prop3_day" id="prop3_day" aria-labelledby="prop3 prop3_day" class="form-select w-20"><option value="" selected="selected">-Choose-</option>
            </select>
            <label style="display:none;" for="prop3_year" id="label_prop3_year">Year</label>
            <select name="prop3_year" id="prop3_year" aria-labelledby="prop3 prop3_year" class="form-select w-20"><option value="" selected="selected">-Choose-</option>
            </select>
            <label style="display:none;" for="prop3_hour" id="label_prop3_hour">Hour</label>
            <select name="prop3_hour" id="prop3_hour" aria-labelledby="prop3 prop3_hour" class="form-select w-20"><option value="" selected="selected">-Choose-</option>
            </select> :
            <label style="display:none;" for="prop3_minute" id="label_prop3_minute">Minute</label>
            <select name="prop3_minute" id="prop3_minute" aria-labelledby="prop3 prop3_minute" class="form-select w-20"></select>
        </div>
    </div>
</div>
</fieldset>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant