0

検証ルールを使用してモデルを設定し、それらをフォームに入力されている情報と比較したいと考えています。今のところ、値が宣言されており、それらが検証されています

Ext.define('FirstApp.view.ReviewsContainer', {
    extend: 'Ext.NavigationView',
    xtype: 'reviewscontainer',


    config: {

        title: 'Reviews',
        iconCls: 'compose',
        items: [{
                xtype: 'reviews'

            }, {
                xtype: 'button',
                align: 'right',
                ui: 'confirm',
                text: 'Leave Review',
                docked: 'bottom',
                centered: 'true',

                handler: function () {
                    if (!this.overlay) {
                        this.overlay = Ext.Viewport.add({
                            xtype: 'formpanel',
                            requires: ['FirstApp.model.ReviewCheck'],
                            id: 'reviewed',
                            modal: true,
                            hideOnMaskTap: true,
                            showAnimation: {
                                type: 'popIn',
                                duration: 250,
                                easing: 'ease-out'
                            },
                            hideAnimation: {
                                type: 'popOut',
                                duration: 250,
                                easing: 'ease-out'
                            },
                            centered: true,
                            width: Ext.os.deviceType == 'Phone' ? 260 : 400,
                            height: Ext.os.deviceType == 'Phone' ? 220 : 400,
                            styleHtmlContent: true,

                            items: [{
                                    docked: 'top',
                                    xtype: 'toolbar',
                                    title: 'Leave Review'
                                },

                                {
                                    xtype: 'fieldset',

                                    title: 'Reviews',
                                    items: [{
                                            xtype: 'textfield',
                                            name: 'name',
                                            label: 'Name',
                                            placeHolder: 'name',
                                            id: 'text'
                                        }, {
                                            xtype: 'textfield',
                                            name: 'business',
                                            label: 'Place'
                                        }, {
                                            xtype: 'textfield',
                                            name: 'rating',
                                            label: 'Rating'
                                        }, {
                                            xtype: 'textareafield',
                                            name: 'review',
                                            label: 'Review'
                                        }
                                    ]
                                }, {
                                    items: [{
                                            xtype: 'button',
                                            text: 'Submit',
                                            ui: 'confirm',
                                            handler: function () {

                                                console.log("Hello");
                                                //var values = Ext.getCmp('reviewed').getValues();

                                                // var text= Ext.getCmp('text').getValue();

                                                //   var value = Ext.ComponentQuery.query('#text')[0].getValue();


                                                //var reviewCheckForm = this.getReviewCheck();
                                                //var currentForm = reviewCheckForm.getRecord();
                                                // var newValues = reviewed.getValues();

                                                // currentForm.set("name", newValues.name);
                                                // currentForm.set("business", newValues.business);
                                                // currentForm.set("review", newValues.review);


                                                var form = formPanel.getForm(); //Get the basicform instance
                                                var record = form.getRecord(); //Get your record loaded in the form
                                                form.updateRecord(record); //Update your record with the current form values
                                                var errors = record.validate(); //Validate your record



                                                // console.log(newValues);
                                                // var data = Ext.create('FirstApp.model.ReviewCheck', {
                                                //         name: 'dfhd',
                                                //     business: 'sdfs',
                                                //     id: 1,
                                                //   review: 'sfsd'
                                                //  });

                                                //   var errors = data.validate();


                                                // var errors = currentForm.validate();
                                                console.log('Number of errors: ' + errors.getCount());




                                                if (!errors.isValid()) {
                                                    console.log('Number of errors: ' + errors.getCount());

                                                    errors.each(function (item, index, length) {
                                                        // Each item in the errors collection is an instance of the Ext.data.Error   class.
                                                        console.log('Field "' + item.getField() + '" ' + item.getMessage());
                                                    });
                                                    Ext.Msg.alert('Form is invalid!');
                                                } else {

                                                    var values = Ext.getCmp('reviewed').getValues();
                                                    // prints the values filled in the form 
                                                    // text fields of name, email and message.     
                                                    console.log(values.name + "," + values.place + "," + values.rating);


                                                    Ext.Ajax.request({
                                                        url: 'http://insert.php',
                                                        params: values,
                                                        success: function (response) {
                                                            var text = response.responseText;
                                                            Ext.getCmp('reviewed').reset();
                                                            Ext.Msg.alert('Success', "Review successfully created.", Ext.getCmp('reviewed').hide(), Ext.StoreMgr.get('Reviews').load());
                                                            console.log("Im Here");
                                                        }
                                                    });
                                                }
                                            }
                                        }
                                    ]
                                }
                            ],
                            scrollable: false
                        });
                    }

                    this.overlay.show();
                }
            }

        ]
    }
})



Ext.define('FirstApp.model.ReviewCheck', {
    extend: 'Ext.data.Model',
    config: {
        fields: [{
                name: 'name',
                type: 'string'
            }, {
                name: 'business',
                type: 'string'
            }, {
                name: 'id',
                type: 'int'
            }, {
                name: 'review',
                type: 'string'
            }
        ], // fields
        validations: [{
                field: 'name',
                type: 'presence',
                error: 'Name must be present',
                message: 'Name is required.'
            }, {
                field: 'business',
                type: 'presence',
                message: 'Place is required.'
            }, {
                field: 'review',
                type: 'presence',
                message: 'Review is required.'

            }
        ] // validations
    } // config
}); // define()

フォームから取得した値に名前、ビジネス、ID、およびレビューを設定するにはどうすればよいですか

4

3 に答える 3

0

フォームのupdateRecord関数を使用できます。@Mayur が彼の例で示したように、すべてのプロパティを手動で設定しないでください。

このようなもの:

{
    xtype: 'button',
    text: 'Submit',
    ui: 'confirm',
    handler: function () {
        var formPanel = this.up('formpanel'); //Get the formpanel
        var form = formPanel.getForm(); //Get the basicform instance
        var record = form.getRecord(); //Get your record loaded in the form
        form.updateRecord(record); //Update your record with the current form values
        var errors = record.validate(); //Validate your record

        console.log('Number of errors: ' + errors.getCount());

        if (!errors.isValid()) {
            console.log('Number of errors: ' + errors.getCount());

            errors.each(function (item, index, length) {
                // Each item in the errors collection is an instance of the Ext.data.Error   class.
                console.log('Field "' + item.getField() + '" ' + item.getMessage());
            });
            Ext.Msg.alert('Form is invalid!');
        } 
        //...
    }
}
于 2013-03-26T10:10:30.317 に答える
0

最初にビューのインスタンスを取得します

var reviewCheckForm = this.getReviewCheck();

次に、そこからレコードを取得します

var currentForm = reviewCheckForm.getRecord();

次に、同じフォームから新しい値を取得します

var newValues = reviewCheckForm.getValues();

次に、新しい値をレコードに設定して検証します

currentForm.set("name", newValues.name);
currentForm.set("business", newValues.business);
currentForm.set("review", newValues.review);

それを検証する

var errors = currentForm.validate();

if (!errors.isValid()) {
    Ext.Msg.alert('Wait!', errors.getByField("title")[0].getMessage(), Ext.emptyFn);
    currentForm.reject();
    return;
}

この簡単なチュートリアルに従って、理解を深め、参考にしてください。モデルの検証部分は次のとおりです。

于 2013-03-26T05:17:31.847 に答える
0

同様の問題があります...JSF + Richfaces基本的に、複数のタブがあります...次のような...(正確なコードではありません)

<rich:tab name="a">
  <inputText id="a1" values="">
  <inputText id="a2" values="">
</rich:tab>

<rich:tab name="b">
  <inputText id="b1" values="">
  <inputText id="b2" values="">
</rich:tab>

手順 1) ユーザーは最初にタブ "a" に移動し、"a1" の値を "newValue" に変更します。2) フォームを送信せずに、タブ "b" に移動します。ユーザーがフォームを送信しなかったため、ユーザーは「タブ a に保存されていないデータがあります」という警告メッセージが表示されるはずです....

これを実装する方法は?

ありがとう..本当に感謝しています。

于 2013-07-18T00:16:39.527 に答える