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 reusing code in TWBootstrapViewStrategyBase for custom html/css not related to Twitter Bootstrap #168

Closed
atsu85 opened this issue Oct 21, 2015 · 3 comments

Comments

@atsu85
Copy link
Contributor

atsu85 commented Oct 21, 2015

Motivation

I'm not using Twitter Bootstrap, so the html/css for my application needs to differ slightly compared to bootstrap html/css - for example instead of:

    <div class="form-group">
      <label>
            First Name
      </label>
      <!-- by default validation message is added here -->
      <input type="text" value.bind="firstName" class="form-control" >
    </div>

I need following layout:

    <p class="field">
      <label>
            First Name
            <!-- need to add validation message here -->
      </label>
      <input type="text" value.bind="firstName" class="form-control" >
    </p>

Proposal

To be able to reuse TWBootstrapViewStrategyBase, following changes need to be made in that class:

  1. export TWBootstrapViewStrategyBase from index.js
  2. allow passing following parameters to the constructor (instead of hard-coded values):
  • formGroupClass = "form-group"
  • validationMsgTagName = "p"
  1. extract code related to inserting helpBlock from findExistingHelpBlock
  2. extract code related to finding existing helpBlock from appendMessageToElement
@atsu85
Copy link
Contributor Author

atsu85 commented Oct 21, 2015

Please merge my pull request #169
to resolve this issue.

@atsu85
Copy link
Contributor Author

atsu85 commented Oct 21, 2015

After merging this pull request, following ViewStrategy will work for the desired example:

import {TWBootstrapViewStrategyBase} from 'aurelia-validation';

export class TKRViewStrategy extends TWBootstrapViewStrategyBase {

  constructor(helpBlockClass: string, formGroupClass: string, validationMsgTagName: string ) {
    super(false, true, helpBlockClass, formGroupClass, validationMsgTagName);
  }

  findExistingHelpBlock(element: Element) {
    var helpBlock: Element = <Element>element.lastChild;
    if (helpBlock) {
      if (!helpBlock.classList) {
        return null;
      }
      else if (!helpBlock.classList.contains(this.helpBlockClass)) {
        return null;
      }
    }
    return helpBlock;
  }

  addHelpBlockToElement(element: Element, helpBlock: Element) {
    element.appendChild(helpBlock);
  }
}

when plugin is configured as follows:

    .plugin('aurelia-validation', (config: ValidationConfig) => {
      config.useViewStrategy(new TKRViewStrategy('custom-validation-msg-class', 'field', 'span'));
    })

atsu85 pushed a commit to atsu85/validation that referenced this issue Oct 22, 2015
This includes 3 pull requests in addition to version 0.3.1:
1) aurelia#166 - aurelia#167 - TypeError: Cannot read property 'classList' of null
2) aurelia#168 - aurelia#169 - makes TWBootstrapViewStrategyBase reusable
3) aurelia#170 - aurelia#171 - Improve generated TypeScript declarations
atsu85 pushed a commit to atsu85/validation that referenced this issue Oct 22, 2015
…le to download custom package with jspm from my repo).

This includes 3 pull requests in addition to version 0.3.1:
1) aurelia#166 - aurelia#167 - TypeError: Cannot read property 'classList' of null
2) aurelia#168 - aurelia#169 - makes TWBootstrapViewStrategyBase reusable
3) aurelia#170 - aurelia#171 - Improve generated TypeScript declarations
@plwalters
Copy link
Contributor

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

2 participants