A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/vuejs/vue/commit/9e38abca3e6ababe0b06dfc9838a90e06ff5ea88 below:

Support select multiple binding (fix #4755) (#4756) · vuejs/vue@9e38abc · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+30

-4

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+30

-4

lines changed Original file line number Diff line number Diff line change

@@ -163,13 +163,14 @@ function genSelect (

163 163

}

164 164 165 165

const number = modifiers && modifiers.number

166 -

const assignment = `Array.prototype.filter` +

166 +

const selectedVal = `Array.prototype.filter` +

167 167

`.call($event.target.options,function(o){return o.selected})` +

168 168

`.map(function(o){var val = "_value" in o ? o._value : o.value;` +

169 -

`return ${number ? '_n(val)' : 'val'}})` +

170 -

(el.attrsMap.multiple == null ? '[0]' : '')

169 +

`return ${number ? '_n(val)' : 'val'}})`

171 170 172 -

const code = genAssignmentCode(value, assignment)

171 +

const assignment = '$event.target.multiple ? $$selectedVal : $$selectedVal[0]'

172 +

let code = `var $$selectedVal = ${selectedVal};`

173 +

code = `${code} ${genAssignmentCode(value, assignment)}`

173 174

addHandler(el, 'change', code, null, true)

174 175

}

175 176 Original file line number Diff line number Diff line change

@@ -262,6 +262,31 @@ describe('Directive v-model select', () => {

262 262

})

263 263

}

264 264 265 +

it('should work with multiple binding', (done) => {

266 +

const spy = jasmine.createSpy()

267 +

const vm = new Vue({

268 +

data: {

269 +

isMultiple: true,

270 +

selections: ['1']

271 +

},

272 +

template:

273 +

'<select v-model="selections" :multiple="isMultiple">' +

274 +

'<option value="1">item 1</option>' +

275 +

'<option value="2">item 2</option>' +

276 +

'</select>',

277 +

watch: {

278 +

selections: spy

279 +

}

280 +

}).$mount()

281 +

document.body.appendChild(vm.$el)

282 +

vm.$el.options[1].selected = true

283 +

triggerEvent(vm.$el, 'change')

284 +

waitForUpdate(() => {

285 +

expect(spy).toHaveBeenCalled()

286 +

expect(vm.selections).toEqual(['1', '2'])

287 +

}).then(done)

288 +

})

289 + 265 290

it('multiple with static template', () => {

266 291

const vm = new Vue({

267 292

template:

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4