Upon the filing of a petition for an order for the commitment of a child to custody, a hearing upon such petition shall be held in open court, and, if the court finds that the petition should be granted, the court shall issue an order for the commitment of the child to custody as petitioned and not otherwise. Written consent of the co-custodians other than the state must be filed with the court before such order for commitment may be issued.