Three young children are in hospital after a trailer became detached from a vehicle and struck a pram while it was being pushed on the pavement in southwestern Scotland.