John Lindal![]()
QueryBuilder provides a way for users to construct a set of filter conditions. The widget is constructed with a set of variables. For each item that the user adds to the list, the user chooses a variable and then a condition for that variable. It is up to the application to decide whether the conditions should be AND'ed or OR'ed.
This example creates a QueryBuilder with five variables: url, impressions, ctr, flag, and submission_status. The validation attached to each variable is compatible with Y.FormManager (gallery-formmgr).
<script src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js"></script>YUI({
//Last Gallery Build of this module
gallery: 'gallery-2013.01.16-21-05'
}).use('gallery-querybuilder', function(Y)
{
var var_list =
[
{
name: 'url',
type: 'string',
text: 'URL',
validation: 'yiv-length:[,3000]'
},
{
name: 'impressions',
type: 'number',
text: 'Impressions (1000s)',
validation: 'yiv-integer'
},
{
name: 'ctr',
type: 'number',
text: 'Click-through rate (%)',
validation: 'yiv-decimal:[0,]'
},
{
name: 'flag',
type: 'select',
text: 'Flagged',
value_list:
[
{ value: "true", text: 'True' },
{ value: "false", text: 'False' }
]
},
{
name: 'submission_status',
type: 'select',
text: 'Status',
value_list:
[
{ value: "I", text: 'Action Required' },
{ value: "S", text: 'Submitted' },
{ value: "A", text: 'Submission Accepted' },
{ value: "B", text: 'Submission Auto-Accepted' }
]
}
];
var ops =
{
string:
[
{ value: 'equal', text: 'Is' },
{ value: 'contains', text: 'Contains' },
{ value: 'starts-with', text: 'Starts with' },
{ value: 'ends-with', text: 'Ends with' }
],
number:
[
{ value: 'equal', text: '= Equals' },
{ value: 'less', text: '< Less than' },
{ value: 'less-equal', text: '<= Less than or equal to' },
{ value: 'greater', text: '> Greater than' },
{ value: 'greater-equal', text: '>= Greater than or equal to' }
],
select:
[
'EQUALS'
]
};
var query = new Y.QueryBuilder(var_list, ops);
query.render('#query');
});
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info