1

2 つの質問:

https://github.com/bwu-dart/bwu_datagrid/blob/master/example/src/composite_editor_item_details/app_element.dart#L120で強調表示されている行を見る

1)なぜ行は

var idx = e.validationResults.errors.length;

常にエラーをスローしますか?

例外: キャッチされないエラー: null オブジェクトには getter 'length' がありません。

NoSuchMethodError: method not found: 'length'
Receiver: null
Arguments: []
Stack Trace:
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#1      validationErrorHandler (http://localhost:8080/epimss_design.html.12.dart:184:42)
#2      _RootZone.runUnaryGuarded (dart:async/zone.dart:1020)
#3      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#4      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:270)
#5      _SyncBroadcastStreamController._sendData (dart:async/broadcast_stream_controller.dart:346)
#6      _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:237)
#7      EventBus.fire (package:bwu_datagrid/core/event_bus.dart:61:19)
#8      _commitCurrentEdit (package:bwu_datagrid/bwu_datagrid.dart:3626:25)
#9      EditorLock.commitCurrentEdit (package:bwu_datagrid/core/range.dart:235:82)
#10     BwuDatagrid._commitEditAndSetFocus (package:bwu_datagrid/bwu_datagrid.dart:3045:40)
#11     _handleKeyDown (package:bwu_datagrid/bwu_datagrid.dart:2632:39)

フィールドや列などの他のプロパティでも同じことが起こります。

2) validationResult が true を返すことをテストするにはどうすればよいですか? エラー ハンドラは、ValidationError が発生した場合にのみ起動するようです。

私のバリデーターを以下に示します

 import 'package:bwu_datagrid/datagrid/helpers.dart' show Column, GridOptions,
    MapDataItem, MapDataItemProvider;
  import 'package:bwu_datagrid/bwu_datagrid.dart' show BwuDatagrid;
  import 'package:bwu_datagrid/formatters/formatters.dart' show CheckmarkFormatter;
  import 'package:bwu_datagrid/editors/editors.dart' show CheckboxEditor, EditorArgs,
    IntegerEditor, TextEditor;
  import 'package:bwu_datagrid/core/core.dart' show AddNewRow, ActiveCellChanged,
    ItemBase, ValidationError;
  import 'package:bwu_datagrid/plugins/row_selection_model.dart' show RowSelectionModel;

  import 'package:epimss_podo/reg.dart' show Email, EMAIL_FORM_EVENT;
  import 'package:epimss_shared/shared.dart' show toggleCoreCollapse, onBwuCellChangeHandler;
  import 'package:epimss_shared/validators.dart' show BwuRequiredEmailValidator,
    BwuRequiredNounValidator;

カスタムバリデータ:

const String REQUIRED_EMAIL_REGEX = r"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b";
const String REQUIRED_NOUN_REGEX = r"\b[a-z'-]{2,}\b";

final RegExp _requiredNounValidator = new RegExp( REQUIRED_NOUN_REGEX, caseSensitive: false );
bool isRequiredNounValid( String property ) =>
    _requiredNounValidator.hasMatch( property );

final RegExp _requiredEmailPropertyValidator = new RegExp( REQUIRED_EMAIL_REGEX, caseSensitive: false );
bool isRequiredEmailPropertyValid( String property ) => _requiredEmailPropertyValidator.hasMatch( property );


class BwuRequiredEmailValidator extends bwu.Validator {
  bwu.ValidationResult call( dynamic value ) {
    if ( isRequiredEmailPropertyValid( value ) ) {
      return new bwu.ValidationResult( true );
    } else {
      return new bwu.ValidationResult( false, 'Valid email address required.' );
    }
  }
}


class BwuRequiredNounValidator extends bwu.Validator {
  bwu.ValidationResult call( dynamic value ) {
    if ( isRequiredNounValid( value) ) {
      return new bwu.ValidationResult( true );
    } else {
      return new bwu.ValidationResult( false, 'Valid noun is required.' );
    }
  }
}

検証エラー ハンドラ:

void validationErrorHandler( ValidationError e ) {
  //print ( e.validationResults.errors.length );
  print ( e.column.field );

  if ( e.validationResults.isValid )
    print( 'retVal is true' );
  else
    print( 'retVal is false' );

  errorMsg = e.validationResults.message;
  var editor = e.editor;
  print ( 'valResult valid |' + e.validationResults.isValid.toString() );

  var result = e.validationResults;

  if ( e.validationResults.isValid ) {
    errorMsg = 'EMAIL';
  } else {
    errorMsg = result.message;
  }

  print( editor.runtimeType ); // aslways print TextEditor

  if ( editor != null ) {
    //var colId = editor.column.id;
    if ( editor is TypeEditor ) {
      email.isTypeValid = true;
    }

    if ( editor is AddressEditor ) {
      email.isAddressValid = false;
    }

    //print( encode ( email ) );
  }
}
4

1 に答える 1